Reset accounts in debug mode

pull/194/head
M66B 4 years ago
parent 2b828c1c5a
commit 535a258410

@ -43,6 +43,7 @@ import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.PopupMenu;
@ -75,6 +76,7 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
private int colorUnread;
private int textColorSecondary;
private boolean debug;
private List<TupleAccountEx> items = new ArrayList<>();
@ -93,6 +95,7 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
private TextView tvUser;
private ImageView ivState;
private TextView tvHost;
private TextView tvCreated;
private TextView tvLast;
private TextView tvUsage;
private TextView tvBackoff;
@ -121,6 +124,7 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
tvUser = itemView.findViewById(R.id.tvUser);
ivState = itemView.findViewById(R.id.ivState);
tvHost = itemView.findViewById(R.id.tvHost);
tvCreated = itemView.findViewById(R.id.tvCreated);
tvLast = itemView.findViewById(R.id.tvLast);
tvUsage = itemView.findViewById(R.id.tvUsage);
tvBackoff = itemView.findViewById(R.id.tvBackoff);
@ -196,6 +200,9 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
ivState.setVisibility(account.synchronize || account.state != null ? View.VISIBLE : View.INVISIBLE);
tvHost.setText(String.format("%s:%d", account.host, account.port));
tvCreated.setVisibility(debug ? View.VISIBLE : View.GONE);
tvCreated.setText(context.getString(R.string.title_created_at,
account.created == null ? null : DTF.format(account.created)));
tvLast.setText(context.getString(R.string.title_last_connected,
(account.last_connected == null ? "-" : DTF.format(account.last_connected)) +
(BuildConfig.DEBUG ?
@ -325,6 +332,9 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
if (account.protocol == EntityAccount.TYPE_IMAP && settings)
popupMenu.getMenu().add(Menu.NONE, R.string.title_copy, 4, R.string.title_copy);
if (debug)
popupMenu.getMenu().add(Menu.NONE, R.string.title_reset, 5, R.string.title_reset);
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
@ -341,6 +351,9 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
} else if (itemId == R.string.title_copy) {
onActionCopy();
return true;
} else if (itemId == R.string.title_reset) {
onActionReset();
return true;
}
return false;
}
@ -433,6 +446,33 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
.putExtra("protocol", account.protocol)
.putExtra("copy", true));
}
private void onActionReset() {
Bundle args = new Bundle();
args.putLong("id", account.id);
new SimpleTask<Void>() {
@Override
protected void onPostExecute(Bundle args) {
ToastEx.makeText(context, R.string.title_completed, Toast.LENGTH_LONG).show();
}
@Override
protected Void onExecute(Context context, Bundle args) throws Throwable {
long id = args.getLong("id");
DB db = DB.getInstance(context);
db.account().resetCreated(id);
return null;
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
}
}.execute(context, owner, args, "account:reset");
}
});
popupMenu.show();
@ -454,6 +494,7 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
int colorHighlight = prefs.getInt("highlight_color", Helper.resolveColor(context, R.attr.colorUnreadHighlight));
this.colorUnread = (highlight_unread ? colorHighlight : Helper.resolveColor(context, R.attr.colorUnread));
this.textColorSecondary = Helper.resolveColor(context, android.R.attr.textColorSecondary);
this.debug = prefs.getBoolean("debug", false);
this.DTF = Helper.getDateTimeInstance(context, DateFormat.SHORT, DateFormat.MEDIUM);

@ -196,6 +196,9 @@ public interface DaoAccount {
@Query("UPDATE account SET `primary` = 0 WHERE NOT (`primary` IS 0)")
void resetPrimary();
@Query("UPDATE account SET `created` = 0 WHERE id = :id")
void resetCreated(long id);
@Query("UPDATE account SET tbd = 1 WHERE id = :id AND NOT (tbd IS 1)")
int setAccountTbd(long id);

@ -144,6 +144,20 @@
app:layout_constraintStart_toEndOf="@+id/ivState"
app:layout_constraintTop_toBottomOf="@id/tvUser" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvCreated"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="6dp"
android:layout_marginEnd="6dp"
android:ellipsize="start"
android:singleLine="true"
android:text="@string/title_created_at"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toStartOf="@id/tvUsage"
app:layout_constraintStart_toEndOf="@+id/ivState"
app:layout_constraintTop_toBottomOf="@id/tvHost" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvLast"
android:layout_width="0dp"
@ -156,7 +170,7 @@
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toStartOf="@id/tvUsage"
app:layout_constraintStart_toEndOf="@+id/ivState"
app:layout_constraintTop_toBottomOf="@id/tvHost" />
app:layout_constraintTop_toBottomOf="@id/tvCreated" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvUsage"

@ -725,6 +725,7 @@
<string name="title_identity_delete">Delete this identity permanently?</string>
<string name="title_edit_html">Edit as HTML</string>
<string name="title_sign_key">Sign key: %1$s</string>
<string name="title_created_at">Created: %1$s</string>
<string name="title_last_connected">Last connected: %1$s</string>
<string name="title_backoff_until">Waiting after failure until: %1$s</string>
<string name="title_storage_quota">Server storage usage: %1$s/%2$s</string>

Loading…
Cancel
Save