mirror of https://github.com/M66B/FairEmail.git
Refactoring
This commit is contained in:
parent
b9fef727af
commit
884615a269
|
@ -38,9 +38,6 @@ public interface DaoAnswer {
|
|||
@Query("SELECT * FROM answer")
|
||||
LiveData<List<EntityAnswer>> liveAnswers();
|
||||
|
||||
@Query("SELECT * FROM answer WHERE id = :id")
|
||||
LiveData<EntityAnswer> liveAnswer(long id);
|
||||
|
||||
@Insert
|
||||
long insertAnswer(EntityAnswer answer);
|
||||
|
||||
|
|
|
@ -72,9 +72,6 @@ public interface DaoFolder {
|
|||
" GROUP BY folder.id")
|
||||
LiveData<List<TupleFolderEx>> liveUnified();
|
||||
|
||||
@Query("SELECT folder.* FROM folder WHERE folder.id = :id")
|
||||
LiveData<EntityFolder> liveFolder(long id);
|
||||
|
||||
@Query("SELECT folder.*, account.name AS accountName" +
|
||||
", COUNT(message.id) AS messages" +
|
||||
", SUM(CASE WHEN message.content = 1 THEN 1 ELSE 0 END) AS content" +
|
||||
|
|
|
@ -52,9 +52,6 @@ public interface DaoIdentity {
|
|||
@Query("SELECT * FROM identity WHERE account = :account AND email = :email")
|
||||
EntityIdentity getIdentity(long account, String email);
|
||||
|
||||
@Query("SELECT * FROM identity WHERE id = :id")
|
||||
LiveData<EntityIdentity> liveIdentity(long id);
|
||||
|
||||
@Query("SELECT COUNT(*) FROM identity WHERE synchronize")
|
||||
int getSynchronizingIdentityCount();
|
||||
|
||||
|
|
|
@ -87,7 +87,6 @@ import androidx.annotation.Nullable;
|
|||
import androidx.constraintlayout.widget.Group;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.lifecycle.Observer;
|
||||
|
||||
import static android.accounts.AccountManager.newChooseAccountIntent;
|
||||
|
||||
|
@ -899,18 +898,18 @@ public class FragmentAccount extends FragmentEx {
|
|||
public void onActivityCreated(@Nullable final Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
||||
final DB db = DB.getInstance(getContext());
|
||||
Bundle args = new Bundle();
|
||||
args.putLong("id", id);
|
||||
|
||||
// Observe
|
||||
db.account().liveAccount(id).observe(getViewLifecycleOwner(), new Observer<EntityAccount>() {
|
||||
private boolean once = false;
|
||||
new SimpleTask<EntityAccount>() {
|
||||
@Override
|
||||
protected EntityAccount onLoad(Context context, Bundle args) throws Throwable {
|
||||
long id = args.getLong("id");
|
||||
return DB.getInstance(context).account().getAccount(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChanged(@Nullable EntityAccount account) {
|
||||
if (once)
|
||||
return;
|
||||
once = true;
|
||||
|
||||
protected void onLoaded(Bundle args, EntityAccount account) {
|
||||
// Get providers
|
||||
List<Provider> providers = Provider.loadProfiles(getContext());
|
||||
providers.add(0, new Provider(getString(R.string.title_select)));
|
||||
|
@ -986,24 +985,24 @@ public class FragmentAccount extends FragmentEx {
|
|||
ibDelete.setVisibility(account == null ? View.GONE : View.VISIBLE);
|
||||
pbWait.setVisibility(View.GONE);
|
||||
|
||||
if (account != null) {
|
||||
db.folder().liveFolders(account.id).observe(getViewLifecycleOwner(), new Observer<List<TupleFolderEx>>() {
|
||||
@Override
|
||||
public void onChanged(final List<TupleFolderEx> _folders) {
|
||||
new Handler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
List<EntityFolder> folders = new ArrayList<>();
|
||||
if (_folders != null)
|
||||
folders.addAll(_folders);
|
||||
setFolders(folders);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
args.putLong("account", account == null ? -1 : account.id);
|
||||
|
||||
new SimpleTask<List<EntityFolder>>() {
|
||||
@Override
|
||||
protected List<EntityFolder> onLoad(Context context, Bundle args) throws Throwable {
|
||||
long account = args.getLong("account");
|
||||
return DB.getInstance(context).folder().getFolders(account);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLoaded(Bundle args, List<EntityFolder> folders) {
|
||||
if (folders == null)
|
||||
folders = new ArrayList<>();
|
||||
setFolders(folders);
|
||||
}
|
||||
}.load(FragmentAccount.this, args);
|
||||
}
|
||||
});
|
||||
}.load(this, args);
|
||||
}
|
||||
|
||||
private void selectAccount() {
|
||||
|
|
|
@ -36,7 +36,6 @@ import androidx.annotation.NonNull;
|
|||
import androidx.annotation.Nullable;
|
||||
import androidx.constraintlayout.widget.Group;
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
import androidx.lifecycle.Observer;
|
||||
|
||||
public class FragmentAnswer extends FragmentEx {
|
||||
private ViewGroup view;
|
||||
|
@ -104,9 +103,18 @@ public class FragmentAnswer extends FragmentEx {
|
|||
public void onActivityCreated(@Nullable final Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
||||
DB.getInstance(getContext()).answer().liveAnswer(id).observe(getViewLifecycleOwner(), new Observer<EntityAnswer>() {
|
||||
Bundle args = new Bundle();
|
||||
args.putLong("id", id);
|
||||
|
||||
new SimpleTask<EntityAnswer>() {
|
||||
@Override
|
||||
public void onChanged(EntityAnswer answer) {
|
||||
protected EntityAnswer onLoad(Context context, Bundle args) throws Throwable {
|
||||
long id = args.getLong("id");
|
||||
return DB.getInstance(context).answer().getAnswer(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLoaded(Bundle args, EntityAnswer answer) {
|
||||
etName.setText(answer == null ? null : answer.name);
|
||||
etText.setText(answer == null ? null : Html.fromHtml(answer.text));
|
||||
bottom_navigation.findViewById(R.id.action_delete).setVisibility(answer == null ? View.GONE : View.VISIBLE);
|
||||
|
@ -114,7 +122,7 @@ public class FragmentAnswer extends FragmentEx {
|
|||
pbWait.setVisibility(View.GONE);
|
||||
grpReady.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
}.load(this, args);
|
||||
}
|
||||
|
||||
private void onActionTrash() {
|
||||
|
|
|
@ -44,7 +44,6 @@ import javax.mail.Session;
|
|||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.lifecycle.Observer;
|
||||
|
||||
public class FragmentFolder extends FragmentEx {
|
||||
private ViewGroup view;
|
||||
|
@ -310,16 +309,18 @@ public class FragmentFolder extends FragmentEx {
|
|||
public void onActivityCreated(@Nullable final Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
||||
// Observe
|
||||
DB.getInstance(getContext()).folder().liveFolder(id).observe(getViewLifecycleOwner(), new Observer<EntityFolder>() {
|
||||
private boolean once = false;
|
||||
Bundle args = new Bundle();
|
||||
args.putLong("id", id);
|
||||
|
||||
new SimpleTask<EntityFolder>() {
|
||||
@Override
|
||||
protected EntityFolder onLoad(Context context, Bundle args) throws Throwable {
|
||||
long id = args.getLong("id");
|
||||
return DB.getInstance(context).folder().getFolder(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChanged(@Nullable final EntityFolder folder) {
|
||||
if (once)
|
||||
return;
|
||||
once = true;
|
||||
|
||||
protected void onLoaded(Bundle args, EntityFolder folder) {
|
||||
if (savedInstanceState == null) {
|
||||
etRename.setText(folder == null ? null : folder.name);
|
||||
etDisplay.setText(folder == null ? null : (folder.display == null ? folder.name : folder.display));
|
||||
|
@ -338,6 +339,6 @@ public class FragmentFolder extends FragmentEx {
|
|||
btnSave.setEnabled(true);
|
||||
ibDelete.setVisibility(folder == null || !EntityFolder.USER.equals(folder.type) ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
});
|
||||
}.load(this, args);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,7 +72,6 @@ import androidx.annotation.NonNull;
|
|||
import androidx.annotation.Nullable;
|
||||
import androidx.constraintlayout.widget.Group;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.lifecycle.Observer;
|
||||
|
||||
public class FragmentIdentity extends FragmentEx {
|
||||
private ViewGroup view;
|
||||
|
@ -609,16 +608,18 @@ public class FragmentIdentity extends FragmentEx {
|
|||
|
||||
final DB db = DB.getInstance(getContext());
|
||||
|
||||
// Observe identity
|
||||
db.identity().liveIdentity(id).observe(getViewLifecycleOwner(), new Observer<EntityIdentity>() {
|
||||
private boolean once = false;
|
||||
Bundle args = new Bundle();
|
||||
args.putLong("id", id);
|
||||
|
||||
new SimpleTask<EntityIdentity>() {
|
||||
@Override
|
||||
protected EntityIdentity onLoad(Context context, Bundle args) throws Throwable {
|
||||
long id = args.getLong("id");
|
||||
return DB.getInstance(context).identity().getIdentity(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChanged(@Nullable final EntityIdentity identity) {
|
||||
if (once)
|
||||
return;
|
||||
once = true;
|
||||
|
||||
protected void onLoaded(Bundle args, final EntityIdentity identity) {
|
||||
if (savedInstanceState == null) {
|
||||
etName.setText(identity == null ? null : identity.name);
|
||||
etEmail.setText(identity == null ? null : identity.email);
|
||||
|
@ -674,16 +675,14 @@ public class FragmentIdentity extends FragmentEx {
|
|||
ibDelete.setVisibility(identity == null ? View.GONE : View.VISIBLE);
|
||||
pbWait.setVisibility(View.GONE);
|
||||
|
||||
db.account().liveAccounts().removeObservers(getViewLifecycleOwner());
|
||||
db.account().liveAccounts().observe(getViewLifecycleOwner(), new Observer<List<EntityAccount>>() {
|
||||
private boolean once = false;
|
||||
new SimpleTask<List<EntityAccount>>() {
|
||||
@Override
|
||||
protected List<EntityAccount> onLoad(Context context, Bundle args) throws Throwable {
|
||||
return DB.getInstance(context).account().getAccounts();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChanged(List<EntityAccount> accounts) {
|
||||
if (once)
|
||||
return;
|
||||
once = true;
|
||||
|
||||
protected void onLoaded(Bundle args, List<EntityAccount> accounts) {
|
||||
if (accounts == null)
|
||||
accounts = new ArrayList<>();
|
||||
|
||||
|
@ -742,9 +741,9 @@ public class FragmentIdentity extends FragmentEx {
|
|||
spAccount.setSelection(account);
|
||||
}
|
||||
}
|
||||
});
|
||||
}.load(FragmentIdentity.this, args);
|
||||
}
|
||||
});
|
||||
}.load(this, args);
|
||||
}
|
||||
|
||||
private void setColor(int color) {
|
||||
|
|
Loading…
Reference in New Issue