Browse Source

Added spinners for account/identity/folder

main
M66B 6 years ago
parent
commit
49ca586a6c
7 changed files with 92 additions and 43 deletions
  1. +23
    -4
      app/src/main/java/eu/faircode/email/FragmentAccount.java
  2. +8
    -7
      app/src/main/java/eu/faircode/email/FragmentFolder.java
  3. +19
    -9
      app/src/main/java/eu/faircode/email/FragmentIdentity.java
  4. +15
    -0
      app/src/main/java/eu/faircode/email/Helper.java
  5. +16
    -11
      app/src/main/res/layout/fragment_account.xml
  6. +0
    -6
      app/src/main/res/layout/fragment_folder.xml
  7. +11
    -6
      app/src/main/res/layout/fragment_identity.xml

+ 23
- 4
app/src/main/java/eu/faircode/email/FragmentAccount.java View File

@ -68,6 +68,7 @@ import androidx.loader.content.Loader;
public class FragmentAccount extends FragmentEx {
private List<Provider> providers;
private ViewGroup view;
private EditText etName;
private Spinner spProfile;
private EditText etHost;
@ -86,8 +87,8 @@ public class FragmentAccount extends FragmentEx {
private Button btnSave;
private ProgressBar pbSave;
private ImageButton ibDelete;
private ProgressBar pbWait;
private Group grpFolders;
// TODO: loading spinner
private ExecutorService executor = Executors.newCachedThreadPool();
@ -96,7 +97,7 @@ public class FragmentAccount extends FragmentEx {
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
setSubtitle(R.string.title_edit_account);
View view = inflater.inflate(R.layout.fragment_account, container, false);
view = (ViewGroup) inflater.inflate(R.layout.fragment_account, container, false);
// Get arguments
Bundle args = getArguments();
@ -125,6 +126,7 @@ public class FragmentAccount extends FragmentEx {
btnSave = view.findViewById(R.id.btnSave);
pbSave = view.findViewById(R.id.pbSave);
ibDelete = view.findViewById(R.id.ibDelete);
pbWait = view.findViewById(R.id.pbWait);
grpFolders = view.findViewById(R.id.grpFolders);
// Wire controls
@ -159,8 +161,11 @@ public class FragmentAccount extends FragmentEx {
btnCheck.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Helper.setViewsEnabled(view, false);
btnCheck.setEnabled(false);
pbCheck.setVisibility(View.VISIBLE);
btnSave.setVisibility(View.GONE);
grpFolders.setVisibility(View.GONE);
Bundle args = new Bundle();
args.putLong("id", id);
@ -180,6 +185,8 @@ public class FragmentAccount extends FragmentEx {
btnSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Helper.setViewsEnabled(view, false);
btnCheck.setEnabled(false);
btnSave.setEnabled(false);
pbSave.setVisibility(View.VISIBLE);
@ -251,12 +258,14 @@ public class FragmentAccount extends FragmentEx {
});
// Initialize
Helper.setViewsEnabled(view, false);
tilPassword.setPasswordVisibilityToggleEnabled(id < 0);
btnCheck.setEnabled(false);
pbCheck.setVisibility(View.GONE);
btnSave.setVisibility(View.GONE);
pbSave.setVisibility(View.GONE);
grpFolders.setVisibility(View.GONE);
ibDelete.setVisibility(id < 0 ? View.GONE : View.VISIBLE);
ibDelete.setVisibility(View.GONE);
return view;
}
@ -283,6 +292,11 @@ public class FragmentAccount extends FragmentEx {
cbSynchronize.setChecked(account == null ? true : account.synchronize);
cbPrimary.setChecked(account == null ? true : account.primary);
cbPrimary.setEnabled(account == null ? true : account.synchronize);
ibDelete.setVisibility(account == null ? View.GONE : View.VISIBLE);
Helper.setViewsEnabled(view, true);
btnCheck.setEnabled(true);
pbWait.setVisibility(View.GONE);
}
});
}
@ -408,6 +422,7 @@ public class FragmentAccount extends FragmentEx {
public void onLoadFinished(@NonNull Loader<CheckData> loader, CheckData data) {
LoaderManager.getInstance(FragmentAccount.this).destroyLoader(loader.getId());
Helper.setViewsEnabled(view, true);
btnCheck.setEnabled(true);
pbCheck.setVisibility(View.GONE);
@ -462,6 +477,8 @@ public class FragmentAccount extends FragmentEx {
} else {
Log.w(Helper.TAG, data.ex + "\n" + Log.getStackTraceString(data.ex));
Toast.makeText(getContext(), Helper.formatThrowable(data.ex), Toast.LENGTH_LONG).show();
grpFolders.setVisibility(View.GONE);
btnSave.setVisibility(View.GONE);
}
}
@ -626,8 +643,10 @@ public class FragmentAccount extends FragmentEx {
public void onLoadFinished(@NonNull Loader<Throwable> loader, Throwable ex) {
LoaderManager.getInstance(FragmentAccount.this).destroyLoader(loader.getId());
Helper.setViewsEnabled(view, true);
btnCheck.setEnabled(true);
btnSave.setEnabled(true);
btnCheck.setVisibility(View.GONE);
pbSave.setVisibility(View.GONE);
if (ex == null)
getFragmentManager().popBackStack();


+ 8
- 7
app/src/main/java/eu/faircode/email/FragmentFolder.java View File

@ -34,26 +34,25 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.Group;
import androidx.lifecycle.Observer;
import androidx.loader.app.LoaderManager;
import androidx.loader.content.AsyncTaskLoader;
import androidx.loader.content.Loader;
public class FragmentFolder extends FragmentEx {
private ViewGroup view;
private CheckBox cbSynchronize;
private EditText etAfter;
private Button btnSave;
private ProgressBar pbSave;
private ProgressBar pbWait;
private Group grpReady;
@Override
@Nullable
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
setSubtitle(R.string.title_edit_folder);
View view = inflater.inflate(R.layout.fragment_folder, container, false);
view = (ViewGroup) inflater.inflate(R.layout.fragment_folder, container, false);
// Get arguments
Bundle args = getArguments();
@ -65,11 +64,11 @@ public class FragmentFolder extends FragmentEx {
pbSave = view.findViewById(R.id.pbSave);
btnSave = view.findViewById(R.id.btnSave);
pbWait = view.findViewById(R.id.pbWait);
grpReady = view.findViewById(R.id.grpReady);
btnSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Helper.setViewsEnabled(view, false);
btnSave.setEnabled(false);
pbSave.setVisibility(View.VISIBLE);
@ -84,11 +83,11 @@ public class FragmentFolder extends FragmentEx {
});
// Initialize
Helper.setViewsEnabled(view, false);
btnSave.setEnabled(false);
pbSave.setVisibility(View.GONE);
grpReady.setVisibility(View.GONE);
pbWait.setVisibility(View.VISIBLE);
return view;
}
@ -110,7 +109,8 @@ public class FragmentFolder extends FragmentEx {
}
pbWait.setVisibility(View.GONE);
grpReady.setVisibility(View.VISIBLE);
Helper.setViewsEnabled(view, true);
btnSave.setEnabled(true);
}
});
}
@ -167,6 +167,7 @@ public class FragmentFolder extends FragmentEx {
public void onLoadFinished(@NonNull Loader<Throwable> loader, Throwable ex) {
LoaderManager.getInstance(FragmentFolder.this).destroyLoader(loader.getId());
Helper.setViewsEnabled(view, true);
btnSave.setEnabled(true);
pbSave.setVisibility(View.GONE);


+ 19
- 9
app/src/main/java/eu/faircode/email/FragmentIdentity.java View File

@ -62,6 +62,7 @@ import androidx.loader.content.Loader;
public class FragmentIdentity extends FragmentEx {
private List<Provider> providers;
private ViewGroup view;
private EditText etName;
private EditText etEmail;
private EditText etReplyTo;
@ -75,9 +76,9 @@ public class FragmentIdentity extends FragmentEx {
private CheckBox cbSynchronize;
private CheckBox cbPrimary;
private Button btnSave;
private ProgressBar pbCheck;
private ProgressBar pbSave;
private ImageButton ibDelete;
// TODO: loading spinner
private ProgressBar pbWait;
private ExecutorService executor = Executors.newCachedThreadPool();
@ -86,7 +87,7 @@ public class FragmentIdentity extends FragmentEx {
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
setSubtitle(R.string.title_edit_identity);
View view = inflater.inflate(R.layout.fragment_identity, container, false);
view = (ViewGroup) inflater.inflate(R.layout.fragment_identity, container, false);
// Get arguments
Bundle args = getArguments();
@ -110,8 +111,9 @@ public class FragmentIdentity extends FragmentEx {
cbSynchronize = view.findViewById(R.id.cbSynchronize);
cbPrimary = view.findViewById(R.id.cbPrimary);
btnSave = view.findViewById(R.id.btnSave);
pbCheck = view.findViewById(R.id.pbCheck);
pbSave = view.findViewById(R.id.pbSave);
ibDelete = view.findViewById(R.id.ibDelete);
pbWait = view.findViewById(R.id.pbWait);
// Wire controls
@ -182,8 +184,9 @@ public class FragmentIdentity extends FragmentEx {
btnSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Helper.setViewsEnabled(view, false);
btnSave.setEnabled(false);
pbCheck.setVisibility(View.VISIBLE);
pbSave.setVisibility(View.VISIBLE);
EntityAccount account = (EntityAccount) spAccount.getSelectedItem();
@ -234,10 +237,11 @@ public class FragmentIdentity extends FragmentEx {
});
// Initialize
etName.requestFocus();
Helper.setViewsEnabled(view, false);
tilPassword.setPasswordVisibilityToggleEnabled(id < 0);
pbCheck.setVisibility(View.GONE);
ibDelete.setVisibility(id < 0 ? View.GONE : View.VISIBLE);
btnSave.setEnabled(false);
pbSave.setVisibility(View.GONE);
ibDelete.setVisibility(View.GONE);
return view;
}
@ -267,6 +271,11 @@ public class FragmentIdentity extends FragmentEx {
cbSynchronize.setChecked(identity == null ? true : identity.synchronize);
cbPrimary.setChecked(identity == null ? true : identity.primary);
cbPrimary.setEnabled(identity == null ? true : identity.synchronize);
ibDelete.setVisibility(identity == null ? View.GONE : View.VISIBLE);
Helper.setViewsEnabled(view, true);
btnSave.setEnabled(true);
pbWait.setVisibility(View.GONE);
db.account().liveAccounts().removeObservers(getViewLifecycleOwner());
db.account().liveAccounts().observe(getViewLifecycleOwner(), new Observer<List<EntityAccount>>() {
@ -403,8 +412,9 @@ public class FragmentIdentity extends FragmentEx {
public void onLoadFinished(@NonNull Loader<Throwable> loader, Throwable ex) {
LoaderManager.getInstance(FragmentIdentity.this).destroyLoader(loader.getId());
Helper.setViewsEnabled(view, true);
btnSave.setEnabled(true);
pbCheck.setVisibility(View.GONE);
pbSave.setVisibility(View.GONE);
if (ex == null)
getFragmentManager().popBackStack();


+ 15
- 0
app/src/main/java/eu/faircode/email/Helper.java View File

@ -27,6 +27,11 @@ import android.graphics.drawable.Drawable;
import android.os.Build;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Spinner;
import java.io.BufferedReader;
import java.io.IOException;
@ -55,6 +60,16 @@ public class Helper {
return mutated;
}
static void setViewsEnabled(ViewGroup view, boolean enabled) {
for (int i = 0; i < view.getChildCount(); i++) {
View child = view.getChildAt(i);
if (child instanceof Spinner || child instanceof EditText || child instanceof CheckBox)
child.setEnabled(enabled);
else if (child instanceof ViewGroup)
setViewsEnabled((ViewGroup) child, enabled);
}
}
static String localizeFolderName(Context context, String name) {
if ("INBOX".equals(name))
return context.getString(R.string.title_folder_inbox);


+ 16
- 11
app/src/main/res/layout/fragment_account.xml View File

@ -198,6 +198,14 @@
app:layout_constraintStart_toEndOf="@id/btnCheck"
app:layout_constraintTop_toTopOf="@id/btnCheck" />
<ImageButton
android:id="@+id/ibDelete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/baseline_delete_24"
app:layout_constraintBottom_toBottomOf="@id/btnCheck"
app:layout_constraintEnd_toEndOf="parent" />
<TextView
android:id="@+id/tvDrafts"
android:layout_width="wrap_content"
@ -311,19 +319,16 @@
app:layout_constraintStart_toEndOf="@id/btnSave"
app:layout_constraintTop_toTopOf="@id/btnSave" />
<ImageButton
android:id="@+id/ibDelete"
<ProgressBar
android:id="@+id/pbWait"
style="@style/Base.Widget.AppCompat.ProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/baseline_delete_24"
app:layout_constraintBottom_toBottomOf="@id/btnSave"
app:layout_constraintEnd_toEndOf="parent" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpReady"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="spProvider,etName,etHost,etPort,etUser,tilPassword,cbPrimary,cbSynchronize,btnCheck" />
android:indeterminate="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpFolders"


+ 0
- 6
app/src/main/res/layout/fragment_folder.xml View File

@ -74,11 +74,5 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpReady"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="cbSynchronize,tvAfter,etAfter,btnSave" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

+ 11
- 6
app/src/main/res/layout/fragment_identity.xml View File

@ -258,7 +258,7 @@
app:layout_constraintTop_toBottomOf="@id/cbPrimary" />
<ProgressBar
android:id="@+id/pbCheck"
android:id="@+id/pbSave"
style="@style/Base.Widget.AppCompat.ProgressBar"
android:layout_width="24dp"
android:layout_height="24dp"
@ -276,10 +276,15 @@
app:layout_constraintBottom_toBottomOf="@id/btnSave"
app:layout_constraintEnd_toEndOf="parent" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpReady"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="etName,etEmail,spProvider,etHost,cbStartTls,etPort,etUser,tilPassword,cbPrimary,cbSynchronize,btnSave" />
<ProgressBar
android:id="@+id/pbWait"
style="@style/Base.Widget.AppCompat.ProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

Loading…
Cancel
Save