Simplify enable state management, improvements

pull/147/head
M66B 6 years ago
parent ec96c352ee
commit ab71106b55

@ -138,6 +138,7 @@ public class FragmentAccount extends FragmentBase {
private Group grpFolders;
private long id = -1;
private boolean saving = false;
private int auth_type = Helper.AUTH_TYPE_PASSWORD;
private int color = Color.TRANSPARENT;
@ -502,21 +503,20 @@ public class FragmentAccount extends FragmentBase {
new SimpleTask<CheckResult>() {
@Override
protected void onPreExecute(Bundle args) {
saving = true;
getActivity().invalidateOptionsMenu();
Helper.setViewsEnabled(view, false);
btnAuthorize.setEnabled(false);
btnCheck.setEnabled(false);
pbCheck.setVisibility(View.VISIBLE);
tvIdle.setVisibility(View.GONE);
grpFolders.setVisibility(View.GONE);
btnSave.setVisibility(View.GONE);
tvError.setVisibility(View.GONE);
}
@Override
protected void onPostExecute(Bundle args) {
saving = false;
getActivity().invalidateOptionsMenu();
Helper.setViewsEnabled(view, true);
btnAuthorize.setEnabled(true);
btnCheck.setEnabled(true);
pbCheck.setVisibility(View.GONE);
}
@ -757,20 +757,18 @@ public class FragmentAccount extends FragmentBase {
new SimpleTask<Void>() {
@Override
protected void onPreExecute(Bundle args) {
saving = true;
getActivity().invalidateOptionsMenu();
Helper.setViewsEnabled(view, false);
btnAuthorize.setEnabled(false);
btnCheck.setEnabled(false);
btnSave.setEnabled(false);
pbSave.setVisibility(View.VISIBLE);
tvError.setVisibility(View.GONE);
}
@Override
protected void onPostExecute(Bundle args) {
saving = false;
getActivity().invalidateOptionsMenu();
Helper.setViewsEnabled(view, true);
btnAuthorize.setEnabled(true);
btnCheck.setEnabled(true);
btnSave.setEnabled(true);
pbSave.setVisibility(View.GONE);
}
@ -1216,7 +1214,7 @@ public class FragmentAccount extends FragmentBase {
@Override
public void onPrepareOptionsMenu(Menu menu) {
menu.findItem(R.id.menu_delete).setVisible(id > 0);
menu.findItem(R.id.menu_delete).setVisible(id > 0 && !saving);
super.onPrepareOptionsMenu(menu);
}
@ -1237,16 +1235,16 @@ public class FragmentAccount extends FragmentBase {
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Helper.setViewsEnabled(view, false);
btnAuthorize.setEnabled(false);
btnCheck.setEnabled(false);
btnSave.setEnabled(false);
pbWait.setVisibility(View.VISIBLE);
Bundle args = new Bundle();
args.putLong("id", id);
new SimpleTask<Void>() {
@Override
protected void onPostExecute(Bundle args) {
Helper.setViewsEnabled(view, false);
pbWait.setVisibility(View.VISIBLE);
}
@Override
protected Void onExecute(Context context, Bundle args) {
long id = args.getLong("id");

@ -61,6 +61,7 @@ public class FragmentFolder extends FragmentBase {
private long id = -1;
private long account = -1;
private boolean saving = false;
private boolean deletable = false;
@Override
@ -159,15 +160,17 @@ public class FragmentFolder extends FragmentBase {
new SimpleTask<Void>() {
@Override
protected void onPreExecute(Bundle args) {
saving = true;
getActivity().invalidateOptionsMenu();
Helper.setViewsEnabled(view, false);
btnSave.setEnabled(false);
pbSave.setVisibility(View.VISIBLE);
}
@Override
protected void onPostExecute(Bundle args) {
saving = false;
getActivity().invalidateOptionsMenu();
Helper.setViewsEnabled(view, true);
btnSave.setEnabled(true);
pbSave.setVisibility(View.GONE);
}
@ -284,7 +287,7 @@ public class FragmentFolder extends FragmentBase {
@Override
public void onPrepareOptionsMenu(Menu menu) {
menu.findItem(R.id.menu_delete).setVisible(id > 0 && deletable);
menu.findItem(R.id.menu_delete).setVisible(id > 0 && !saving && deletable);
super.onPrepareOptionsMenu(menu);
}
@ -306,7 +309,6 @@ public class FragmentFolder extends FragmentBase {
@Override
public void onClick(DialogInterface dialog, int which) {
Helper.setViewsEnabled(view, false);
btnSave.setEnabled(false);
pbSave.setVisibility(View.VISIBLE);
Bundle args = new Bundle();
@ -338,7 +340,6 @@ public class FragmentFolder extends FragmentBase {
@Override
protected void onException(Bundle args, Throwable ex) {
Helper.setViewsEnabled(view, true);
btnSave.setEnabled(true);
pbSave.setVisibility(View.GONE);
if (ex instanceof IllegalArgumentException)

@ -114,6 +114,7 @@ public class FragmentIdentity extends FragmentBase {
private Group grpAdvanced;
private long id = -1;
private boolean saving = false;
private int auth_type = Helper.AUTH_TYPE_PASSWORD;
private int color = Color.TRANSPARENT;
@ -483,16 +484,18 @@ public class FragmentIdentity extends FragmentBase {
new SimpleTask<Void>() {
@Override
protected void onPreExecute(Bundle args) {
saving = true;
getActivity().invalidateOptionsMenu();
Helper.setViewsEnabled(view, false);
btnSave.setEnabled(false);
pbSave.setVisibility(View.VISIBLE);
tvError.setVisibility(View.GONE);
}
@Override
protected void onPostExecute(Bundle args) {
saving = false;
getActivity().invalidateOptionsMenu();
Helper.setViewsEnabled(view, true);
btnSave.setEnabled(true);
pbSave.setVisibility(View.GONE);
}
@ -854,7 +857,7 @@ public class FragmentIdentity extends FragmentBase {
@Override
public void onPrepareOptionsMenu(Menu menu) {
menu.findItem(R.id.menu_delete).setVisible(id > 0);
menu.findItem(R.id.menu_delete).setVisible(id > 0 && !saving);
super.onPrepareOptionsMenu(menu);
}
@ -875,14 +878,16 @@ public class FragmentIdentity extends FragmentBase {
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Helper.setViewsEnabled(view, false);
btnSave.setEnabled(false);
pbWait.setVisibility(View.VISIBLE);
Bundle args = new Bundle();
args.putLong("id", id);
new SimpleTask<Void>() {
@Override
protected void onPostExecute(Bundle args) {
Helper.setViewsEnabled(view, false);
pbWait.setVisibility(View.VISIBLE);
}
@Override
protected Void onExecute(Context context, Bundle args) {
long id = args.getLong("id");
@ -919,9 +924,4 @@ public class FragmentIdentity extends FragmentBase {
border.setStroke(1, Helper.resolveColor(getContext(), R.attr.colorSeparator));
vwColor.setBackground(border);
}
class IdentityFolders {
EntityIdentity identity;
List<EntityFolder> folders;
}
}

@ -45,6 +45,7 @@ import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
@ -223,7 +224,8 @@ public class Helper {
if (child instanceof Spinner ||
child instanceof EditText ||
child instanceof CheckBox ||
child instanceof ImageView /* =ImageButton */)
child instanceof ImageView /* =ImageButton */ ||
(child instanceof Button && "disable".equals(child.getTag())))
child.setEnabled(enabled);
if (child instanceof BottomNavigationView) {
Menu menu = ((BottomNavigationView) child).getMenu();

@ -70,6 +70,7 @@
android:layout_marginTop="12dp"
android:minWidth="0dp"
android:minHeight="0dp"
android:tag="disable"
android:text="@string/title_autoconfig"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etDomain" />
@ -166,6 +167,7 @@
android:layout_marginTop="12dp"
android:minWidth="0dp"
android:minHeight="0dp"
android:tag="disable"
android:text="@string/title_authorize"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etPort" />
@ -281,6 +283,7 @@
android:layout_marginTop="12dp"
android:minWidth="0dp"
android:minHeight="0dp"
android:tag="disable"
android:text="@string/title_account_color"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etName" />
@ -423,6 +426,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:tag="disable"
android:text="@string/title_check"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etPrefix" />
@ -613,6 +617,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:tag="disable"
android:text="@string/title_save"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/spRight" />

@ -173,6 +173,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:tag="disable"
android:text="@string/title_save"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbKeepAll" />

@ -105,6 +105,7 @@
android:layout_marginTop="12dp"
android:minWidth="0dp"
android:minHeight="0dp"
android:tag="disable"
android:text="@string/title_account_color"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etDisplay" />
@ -158,6 +159,7 @@
android:layout_height="wrap_content"
android:minWidth="0dp"
android:minHeight="0dp"
android:tag="disable"
android:text="@string/title_edit_html"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etSignature" />
@ -235,6 +237,7 @@
android:layout_marginTop="12dp"
android:minWidth="0dp"
android:minHeight="0dp"
android:tag="disable"
android:text="@string/title_autoconfig"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etDomain" />
@ -497,6 +500,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:tag="disable"
android:text="@string/title_save"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvStoreSent" />

Loading…
Cancel
Save