Moved observers and loaders to onActivityCreate

pull/30/head
M66B 7 years ago
parent b0d8bc9c10
commit ab5f432978

@ -188,6 +188,17 @@ public class FragmentAccount extends FragmentEx {
pbCheck.setVisibility(View.GONE); pbCheck.setVisibility(View.GONE);
ibDelete.setVisibility(id < 0 ? View.GONE : View.VISIBLE); ibDelete.setVisibility(id < 0 ? View.GONE : View.VISIBLE);
return view;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// Get arguments
Bundle args = getArguments();
long id = (args == null ? -1 : args.getLong("id", -1));
// Observe // Observe
DB.getInstance(getContext()).account().liveAccount(id).observe(this, new Observer<EntityAccount>() { DB.getInstance(getContext()).account().liveAccount(id).observe(this, new Observer<EntityAccount>() {
@Override @Override
@ -202,8 +213,6 @@ public class FragmentAccount extends FragmentEx {
cbPrimary.setEnabled(account == null ? true : account.synchronize); cbPrimary.setEnabled(account == null ? true : account.synchronize);
} }
}); });
return view;
} }
private static class PutLoader extends AsyncTaskLoader<Throwable> { private static class PutLoader extends AsyncTaskLoader<Throwable> {

@ -80,6 +80,13 @@ public class FragmentAccounts extends FragmentEx {
grpReady.setVisibility(View.GONE); grpReady.setVisibility(View.GONE);
pbWait.setVisibility(View.VISIBLE); pbWait.setVisibility(View.VISIBLE);
return view;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// Observe accounts // Observe accounts
DB.getInstance(getContext()).account().liveAccounts().observe(this, new Observer<List<EntityAccount>>() { DB.getInstance(getContext()).account().liveAccounts().observe(this, new Observer<List<EntityAccount>>() {
@Override @Override
@ -90,7 +97,5 @@ public class FragmentAccounts extends FragmentEx {
grpReady.setVisibility(View.VISIBLE); grpReady.setVisibility(View.VISIBLE);
} }
}); });
return view;
} }
} }

@ -93,7 +93,7 @@ public class FragmentCompose extends FragmentEx {
// Get arguments // Get arguments
Bundle args = getArguments(); Bundle args = getArguments();
String action = (args == null ? null : args.getString("action")); String action = (args == null ? null : args.getString("action"));
final long id = (TextUtils.isEmpty(action) ? (args == null ? -1 : args.getLong("id" , -1)) : -1); final long id = (TextUtils.isEmpty(action) ? (args == null ? -1 : args.getLong("id", -1)) : -1);
// Get controls // Get controls
spFrom = view.findViewById(R.id.spFrom); spFrom = view.findViewById(R.id.spFrom);
@ -117,7 +117,7 @@ public class FragmentCompose extends FragmentEx {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("id" , -1); args.putLong("id", -1);
FragmentIdentity fragment = new FragmentIdentity(); FragmentIdentity fragment = new FragmentIdentity();
fragment.setArguments(args); fragment.setArguments(args);
@ -181,7 +181,12 @@ public class FragmentCompose extends FragmentEx {
pbWait.setVisibility(View.VISIBLE); pbWait.setVisibility(View.VISIBLE);
bottom_navigation.getMenu().setGroupEnabled(0, false); bottom_navigation.getMenu().setGroupEnabled(0, false);
final Handler handler = new Handler(); return view;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
DB.getInstance(getContext()).identity().liveIdentities(true).observe(FragmentCompose.this, new Observer<List<EntityIdentity>>() { DB.getInstance(getContext()).identity().liveIdentities(true).observe(FragmentCompose.this, new Observer<List<EntityIdentity>>() {
@Override @Override
@ -207,19 +212,10 @@ public class FragmentCompose extends FragmentEx {
spFrom.setVisibility(View.VISIBLE); spFrom.setVisibility(View.VISIBLE);
ivIdentityAdd.setVisibility(View.VISIBLE); ivIdentityAdd.setVisibility(View.VISIBLE);
// For some reason this is needed to make sure the loader starts // Get might select another identity
handler.post(new Runnable() { getLoaderManager().restartLoader(ActivityCompose.LOADER_COMPOSE_GET, getArguments(), getLoaderCallbacks).forceLoad();
@Override
public void run() {
// Get might select another identity
getLoaderManager().restartLoader(ActivityCompose.LOADER_COMPOSE_GET, getArguments(), getLoaderCallbacks).forceLoad();
}
});
} }
}); });
return view;
} }
@Override @Override
@ -298,16 +294,16 @@ public class FragmentCompose extends FragmentEx {
EntityIdentity identity = (EntityIdentity) spFrom.getSelectedItem(); EntityIdentity identity = (EntityIdentity) spFrom.getSelectedItem();
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("id" , id); args.putLong("id", id);
args.putLong("iid" , identity == null ? -1 : identity.id); args.putLong("iid", identity == null ? -1 : identity.id);
args.putString("thread" , FragmentCompose.this.thread); args.putString("thread", FragmentCompose.this.thread);
args.putLong("rid" , FragmentCompose.this.rid); args.putLong("rid", FragmentCompose.this.rid);
args.putString("to" , etTo.getText().toString()); args.putString("to", etTo.getText().toString());
args.putString("cc" , etCc.getText().toString()); args.putString("cc", etCc.getText().toString());
args.putString("bcc" , etBcc.getText().toString()); args.putString("bcc", etBcc.getText().toString());
args.putString("subject" , etSubject.getText().toString()); args.putString("subject", etSubject.getText().toString());
args.putString("body" , etBody.getText().toString()); args.putString("body", etBody.getText().toString());
args.putString("action" , action); args.putString("action", action);
getLoaderManager().restartLoader(ActivityCompose.LOADER_COMPOSE_PUT, args, putLoaderCallbacks).forceLoad(); getLoaderManager().restartLoader(ActivityCompose.LOADER_COMPOSE_PUT, args, putLoaderCallbacks).forceLoad();
} }
@ -329,35 +325,35 @@ public class FragmentCompose extends FragmentEx {
Bundle result = new Bundle(); Bundle result = new Bundle();
try { try {
String action = args.getString("action"); String action = args.getString("action");
long id = args.getLong("id" , -1); long id = args.getLong("id", -1);
EntityMessage msg = DB.getInstance(getContext()).message().getMessage(id); EntityMessage msg = DB.getInstance(getContext()).message().getMessage(id);
result.putString("action" , action); result.putString("action", action);
if (msg != null) { if (msg != null) {
if (msg.identity != null) if (msg.identity != null)
result.putLong("iid" , msg.identity); result.putLong("iid", msg.identity);
if (msg.replying != null) if (msg.replying != null)
result.putLong("rid" , msg.replying); result.putLong("rid", msg.replying);
result.putSerializable("cc" , msg.cc); result.putSerializable("cc", msg.cc);
result.putSerializable("bcc" , msg.bcc); result.putSerializable("bcc", msg.bcc);
result.putString("thread" , msg.thread); result.putString("thread", msg.thread);
result.putString("subject" , msg.subject); result.putString("subject", msg.subject);
result.putString("body" , msg.body); result.putString("body", msg.body);
} }
if (TextUtils.isEmpty(action)) { if (TextUtils.isEmpty(action)) {
if (msg != null) { if (msg != null) {
result.putSerializable("from" , msg.from); result.putSerializable("from", msg.from);
result.putSerializable("to" , msg.to); result.putSerializable("to", msg.to);
} }
} else if ("reply".equals(action)) { } else if ("reply".equals(action)) {
Address[] to = null; Address[] to = null;
if (msg != null) if (msg != null)
to = (msg.reply == null || msg.reply.length == 0 ? msg.from : msg.reply); to = (msg.reply == null || msg.reply.length == 0 ? msg.from : msg.reply);
result.putLong("rid" , msg.id); result.putLong("rid", msg.id);
result.putSerializable("from" , msg.to); result.putSerializable("from", msg.to);
result.putSerializable("to" , to); result.putSerializable("to", to);
} else if ("reply_all".equals(action)) { } else if ("reply_all".equals(action)) {
Address[] to = null; Address[] to = null;
if (msg != null) { if (msg != null) {
@ -370,15 +366,15 @@ public class FragmentCompose extends FragmentEx {
addresses.addAll(Arrays.asList(msg.cc)); addresses.addAll(Arrays.asList(msg.cc));
to = addresses.toArray(new Address[0]); to = addresses.toArray(new Address[0]);
} }
result.putLong("rid" , msg.id); result.putLong("rid", msg.id);
result.putSerializable("from" , msg.to); result.putSerializable("from", msg.to);
result.putSerializable("to" , to); result.putSerializable("to", to);
} else if ("forward".equals(action)) { } else if ("forward".equals(action)) {
Address[] to = null; Address[] to = null;
if (msg != null) if (msg != null)
to = (msg.reply == null || msg.reply.length == 0 ? msg.from : msg.reply); to = (msg.reply == null || msg.reply.length == 0 ? msg.from : msg.reply);
result.putSerializable("from" , msg.to); result.putSerializable("from", msg.to);
result.putSerializable("to" , to); result.putSerializable("to", to);
} }
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex)); Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
@ -400,8 +396,8 @@ public class FragmentCompose extends FragmentEx {
public void onLoadFinished(@NonNull Loader<Bundle> loader, Bundle result) { public void onLoadFinished(@NonNull Loader<Bundle> loader, Bundle result) {
getLoaderManager().destroyLoader(loader.getId()); getLoaderManager().destroyLoader(loader.getId());
long iid = result.getLong("iid" , -1); long iid = result.getLong("iid", -1);
long rid = result.getLong("rid" , -1); long rid = result.getLong("rid", -1);
String thread = result.getString("thread"); String thread = result.getString("thread");
Address[] from = (Address[]) result.getSerializable("from"); Address[] from = (Address[]) result.getSerializable("from");
Address[] to = (Address[]) result.getSerializable("to"); Address[] to = (Address[]) result.getSerializable("to");
@ -437,11 +433,11 @@ public class FragmentCompose extends FragmentEx {
Handler handler = new Handler(); Handler handler = new Handler();
etCc.setText(cc == null ? null : TextUtils.join(", " , cc)); etCc.setText(cc == null ? null : TextUtils.join(", ", cc));
etBcc.setText(bcc == null ? null : TextUtils.join(", " , bcc)); etBcc.setText(bcc == null ? null : TextUtils.join(", ", bcc));
if (action == null) { if (action == null) {
etTo.setText(to == null ? null : TextUtils.join(", " , to)); etTo.setText(to == null ? null : TextUtils.join(", ", to));
etSubject.setText(subject); etSubject.setText(subject);
if (body != null) if (body != null)
etBody.setText(Html.fromHtml(HtmlHelper.sanitize(getContext(), body, false))); etBody.setText(Html.fromHtml(HtmlHelper.sanitize(getContext(), body, false)));
@ -452,10 +448,10 @@ public class FragmentCompose extends FragmentEx {
} }
}); });
} else if ("reply".equals(action) || "reply_all".equals(action)) { } else if ("reply".equals(action) || "reply_all".equals(action)) {
etTo.setText(to == null ? null : TextUtils.join(", " , to)); etTo.setText(to == null ? null : TextUtils.join(", ", to));
String text = String.format("<br><br>%s %s:<br><br>%s" , String text = String.format("<br><br>%s %s:<br><br>%s",
Html.escapeHtml(new Date().toString()), Html.escapeHtml(new Date().toString()),
Html.escapeHtml(to == null ? "" : TextUtils.join(", " , to)), Html.escapeHtml(to == null ? "" : TextUtils.join(", ", to)),
HtmlHelper.sanitize(getContext(), body, true)); HtmlHelper.sanitize(getContext(), body, true));
etSubject.setText(getContext().getString(R.string.title_subject_reply, subject)); etSubject.setText(getContext().getString(R.string.title_subject_reply, subject));
etBody.setText(Html.fromHtml(text)); etBody.setText(Html.fromHtml(text));
@ -466,9 +462,9 @@ public class FragmentCompose extends FragmentEx {
} }
}); });
} else if ("forward".equals(action)) { } else if ("forward".equals(action)) {
String text = String.format("<br><br>%s %s:<br><br>%s" , String text = String.format("<br><br>%s %s:<br><br>%s",
Html.escapeHtml(new Date().toString()), Html.escapeHtml(new Date().toString()),
Html.escapeHtml(to == null ? "" : TextUtils.join(", " , to)), Html.escapeHtml(to == null ? "" : TextUtils.join(", ", to)),
HtmlHelper.sanitize(getContext(), body, true)); HtmlHelper.sanitize(getContext(), body, true));
etSubject.setText(getContext().getString(R.string.title_subject_forward, subject)); etSubject.setText(getContext().getString(R.string.title_subject_forward, subject));
etBody.setText(Html.fromHtml(text)); etBody.setText(Html.fromHtml(text));
@ -519,7 +515,7 @@ public class FragmentCompose extends FragmentEx {
if (drafts == null) if (drafts == null)
throw new Throwable(getContext().getString(R.string.title_no_primary_drafts)); throw new Throwable(getContext().getString(R.string.title_no_primary_drafts));
long rid = args.getLong("rid" , -1); long rid = args.getLong("rid", -1);
String thread = args.getString("thread"); String thread = args.getString("thread");
String to = args.getString("to"); String to = args.getString("to");
String cc = args.getString("cc"); String cc = args.getString("cc");
@ -546,7 +542,7 @@ public class FragmentCompose extends FragmentEx {
draft.cc = acc; draft.cc = acc;
draft.bcc = abcc; draft.bcc = abcc;
draft.subject = subject; draft.subject = subject;
draft.body = "<pre>" + body.replaceAll("\\r?\\n" , "<br />") + "</pre>"; draft.body = "<pre>" + body.replaceAll("\\r?\\n", "<br />") + "</pre>";
draft.received = new Date().getTime(); draft.received = new Date().getTime();
draft.seen = false; draft.seen = false;
draft.ui_seen = false; draft.ui_seen = false;

@ -73,9 +73,9 @@ public class FragmentFolder extends FragmentEx {
pbSave.setVisibility(View.VISIBLE); pbSave.setVisibility(View.VISIBLE);
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("id" , id); args.putLong("id", id);
args.putBoolean("synchronize" , cbSynchronize.isChecked()); args.putBoolean("synchronize", cbSynchronize.isChecked());
args.putString("after" , etAfter.getText().toString()); args.putString("after", etAfter.getText().toString());
getLoaderManager().restartLoader(ActivityView.LOADER_FOLDER_PUT, args, putLoaderCallbacks).forceLoad(); getLoaderManager().restartLoader(ActivityView.LOADER_FOLDER_PUT, args, putLoaderCallbacks).forceLoad();
} }
@ -86,6 +86,18 @@ public class FragmentFolder extends FragmentEx {
grpReady.setVisibility(View.GONE); grpReady.setVisibility(View.GONE);
pbWait.setVisibility(View.VISIBLE); pbWait.setVisibility(View.VISIBLE);
return view;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// Get arguments
Bundle args = getArguments();
long id = (args == null ? -1 : args.getLong("id"));
// Observe // Observe
DB.getInstance(getContext()).folder().liveFolder(id).observe(this, new Observer<EntityFolder>() { DB.getInstance(getContext()).folder().liveFolder(id).observe(this, new Observer<EntityFolder>() {
@Override @Override
@ -99,8 +111,6 @@ public class FragmentFolder extends FragmentEx {
grpReady.setVisibility(View.VISIBLE); grpReady.setVisibility(View.VISIBLE);
} }
}); });
return view;
} }
private static class PutLoader extends AsyncTaskLoader<Throwable> { private static class PutLoader extends AsyncTaskLoader<Throwable> {

@ -48,10 +48,6 @@ public class FragmentFolders extends FragmentEx {
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_folders, container, false); View view = inflater.inflate(R.layout.fragment_folders, container, false);
// Get arguments
Bundle args = getArguments();
long account = (args == null ? -1 : args.getLong("account"));
// Get controls // Get controls
rvFolder = view.findViewById(R.id.rvFolder); rvFolder = view.findViewById(R.id.rvFolder);
pbWait = view.findViewById(R.id.pbWait); pbWait = view.findViewById(R.id.pbWait);
@ -78,6 +74,17 @@ public class FragmentFolders extends FragmentEx {
grpReady.setVisibility(View.GONE); grpReady.setVisibility(View.GONE);
pbWait.setVisibility(View.VISIBLE); pbWait.setVisibility(View.VISIBLE);
return view;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// Get arguments
Bundle args = getArguments();
long account = (args == null ? -1 : args.getLong("account"));
DB db = DB.getInstance(getContext()); DB db = DB.getInstance(getContext());
// Observe account // Observe account
@ -100,8 +107,7 @@ public class FragmentFolders extends FragmentEx {
}); });
// Show hint // Show hint
// TODO: find better solution
Toast.makeText(getContext(), R.string.title_item_edit_hint, Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), R.string.title_item_edit_hint, Toast.LENGTH_SHORT).show();
return view;
} }
} }

@ -80,6 +80,13 @@ public class FragmentIdentities extends FragmentEx {
grpReady.setVisibility(View.GONE); grpReady.setVisibility(View.GONE);
pbWait.setVisibility(View.VISIBLE); pbWait.setVisibility(View.VISIBLE);
return view;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// Observe identities // Observe identities
DB.getInstance(getContext()).identity().liveIdentities().observe(this, new Observer<List<EntityIdentity>>() { DB.getInstance(getContext()).identity().liveIdentities().observe(this, new Observer<List<EntityIdentity>>() {
@Override @Override
@ -90,7 +97,5 @@ public class FragmentIdentities extends FragmentEx {
grpReady.setVisibility(View.VISIBLE); grpReady.setVisibility(View.VISIBLE);
} }
}); });
return view;
} }
} }

@ -87,7 +87,7 @@ public class FragmentIdentity extends FragmentEx {
// Get arguments // Get arguments
Bundle args = getArguments(); Bundle args = getArguments();
final long id = (args == null ? -1 : args.getLong("id" , -1)); final long id = (args == null ? -1 : args.getLong("id", -1));
// Get providers // Get providers
providers = Provider.loadProfiles(getContext()); providers = Provider.loadProfiles(getContext());
@ -167,17 +167,17 @@ public class FragmentIdentity extends FragmentEx {
pbCheck.setVisibility(View.VISIBLE); pbCheck.setVisibility(View.VISIBLE);
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("id" , id); args.putLong("id", id);
args.putString("name" , etName.getText().toString()); args.putString("name", etName.getText().toString());
args.putString("email" , etEmail.getText().toString()); args.putString("email", etEmail.getText().toString());
args.putString("replyto" , etReplyTo.getText().toString()); args.putString("replyto", etReplyTo.getText().toString());
args.putString("host" , etHost.getText().toString()); args.putString("host", etHost.getText().toString());
args.putBoolean("starttls" , cbStartTls.isChecked()); args.putBoolean("starttls", cbStartTls.isChecked());
args.putString("port" , etPort.getText().toString()); args.putString("port", etPort.getText().toString());
args.putString("user" , etUser.getText().toString()); args.putString("user", etUser.getText().toString());
args.putString("password" , tilPassword.getEditText().getText().toString()); args.putString("password", tilPassword.getEditText().getText().toString());
args.putBoolean("synchronize" , cbSynchronize.isChecked()); args.putBoolean("synchronize", cbSynchronize.isChecked());
args.putBoolean("primary" , cbPrimary.isChecked()); args.putBoolean("primary", cbPrimary.isChecked());
getLoaderManager().restartLoader(ActivityView.LOADER_IDENTITY_PUT, args, putLoaderCallbacks).forceLoad(); getLoaderManager().restartLoader(ActivityView.LOADER_IDENTITY_PUT, args, putLoaderCallbacks).forceLoad();
} }
@ -216,6 +216,17 @@ public class FragmentIdentity extends FragmentEx {
pbCheck.setVisibility(View.GONE); pbCheck.setVisibility(View.GONE);
ibDelete.setVisibility(id < 0 ? View.GONE : View.VISIBLE); ibDelete.setVisibility(id < 0 ? View.GONE : View.VISIBLE);
return view;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// Get arguments
Bundle args = getArguments();
long id = (args == null ? -1 : args.getLong("id", -1));
// Observer // Observer
DB.getInstance(getContext()).identity().liveIdentity(id).observe(this, new Observer<EntityIdentity>() { DB.getInstance(getContext()).identity().liveIdentity(id).observe(this, new Observer<EntityIdentity>() {
@Override @Override
@ -233,8 +244,6 @@ public class FragmentIdentity extends FragmentEx {
cbPrimary.setEnabled(identity == null ? true : identity.synchronize); cbPrimary.setEnabled(identity == null ? true : identity.synchronize);
} }
}); });
return view;
} }
private static class PutLoader extends AsyncTaskLoader<Throwable> { private static class PutLoader extends AsyncTaskLoader<Throwable> {

@ -222,6 +222,17 @@ public class FragmentMessage extends FragmentEx {
adapter = new AdapterAttachment(getContext()); adapter = new AdapterAttachment(getContext());
rvAttachment.setAdapter(adapter); rvAttachment.setAdapter(adapter);
return view;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// Get arguments
Bundle args = getArguments();
final long id = (args == null ? -1 : args.getLong("id"));
final DB db = DB.getInstance(getContext()); final DB db = DB.getInstance(getContext());
// Observe message // Observe message
@ -254,8 +265,8 @@ public class FragmentMessage extends FragmentEx {
tvFrom.setTextColor(colorUnseen); tvFrom.setTextColor(colorUnseen);
tvTime.setTextColor(colorUnseen); tvTime.setTextColor(colorUnseen);
DB.getInstance(getContext()).attachment().liveAttachments(id).removeObservers(FragmentMessage.this); db.attachment().liveAttachments(id).removeObservers(FragmentMessage.this);
DB.getInstance(getContext()).attachment().liveAttachments(id).observe(FragmentMessage.this, db.attachment().liveAttachments(id).observe(FragmentMessage.this,
new Observer<List<TupleAttachment>>() { new Observer<List<TupleAttachment>>() {
@Override @Override
public void onChanged(@Nullable List<TupleAttachment> attachments) { public void onChanged(@Nullable List<TupleAttachment> attachments) {
@ -313,8 +324,6 @@ public class FragmentMessage extends FragmentEx {
grpReady.setVisibility(View.VISIBLE); grpReady.setVisibility(View.VISIBLE);
} }
}); });
return view;
} }
@Override @Override

@ -61,8 +61,7 @@ public class FragmentMessages extends FragmentEx {
// Get arguments // Get arguments
Bundle args = getArguments(); Bundle args = getArguments();
long folder = (args == null ? -1 : args.getLong("folder" , -1)); long thread = (args == null ? -1 : args.getLong("thread", -1)); // message ID
long thread = (args == null ? -1 : args.getLong("thread" , -1)); // message ID
// Get controls // Get controls
rvMessage = view.findViewById(R.id.rvFolder); rvMessage = view.findViewById(R.id.rvFolder);
@ -96,10 +95,22 @@ public class FragmentMessages extends FragmentEx {
pbWait.setVisibility(View.VISIBLE); pbWait.setVisibility(View.VISIBLE);
fab.setVisibility(View.GONE); fab.setVisibility(View.GONE);
return view;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// Get arguments
Bundle args = getArguments();
long folder = (args == null ? -1 : args.getLong("folder", -1));
long thread = (args == null ? -1 : args.getLong("thread", -1)); // message ID
// Observe folder/messages // Observe folder/messages
DB db = DB.getInstance(getContext()); DB db = DB.getInstance(getContext());
LiveData<PagedList<TupleMessageEx>> messages; LiveData<PagedList<TupleMessageEx>> messages;
boolean debug = PreferenceManager.getDefaultSharedPreferences(getContext()).getBoolean("debug" , false); boolean debug = PreferenceManager.getDefaultSharedPreferences(getContext()).getBoolean("debug", false);
if (thread < 0) if (thread < 0)
if (folder < 0) { if (folder < 0) {
setSubtitle(R.string.title_folder_unified); setSubtitle(R.string.title_folder_unified);
@ -118,9 +129,11 @@ public class FragmentMessages extends FragmentEx {
messages = new LivePagedListBuilder<>(db.message().pagedThread(thread, debug), PAGE_SIZE).build(); messages = new LivePagedListBuilder<>(db.message().pagedThread(thread, debug), PAGE_SIZE).build();
} }
Log.i(Helper.TAG, "Observing messages");
messages.observe(this, new Observer<PagedList<TupleMessageEx>>() { messages.observe(this, new Observer<PagedList<TupleMessageEx>>() {
@Override @Override
public void onChanged(@Nullable PagedList<TupleMessageEx> messages) { public void onChanged(@Nullable PagedList<TupleMessageEx> messages) {
Log.i(Helper.TAG, "Submit messages=" + messages.size());
adapter.submitList(messages); adapter.submitList(messages);
pbWait.setVisibility(View.GONE); pbWait.setVisibility(View.GONE);
@ -137,8 +150,6 @@ public class FragmentMessages extends FragmentEx {
}); });
getLoaderManager().restartLoader(ActivityView.LOADER_MESSAGES_INIT, new Bundle(), initLoaderCallbacks).forceLoad(); getLoaderManager().restartLoader(ActivityView.LOADER_MESSAGES_INIT, new Bundle(), initLoaderCallbacks).forceLoad();
return view;
} }
private static class InitLoader extends AsyncTaskLoader<Bundle> { private static class InitLoader extends AsyncTaskLoader<Bundle> {
@ -152,10 +163,10 @@ public class FragmentMessages extends FragmentEx {
Bundle result = new Bundle(); Bundle result = new Bundle();
try { try {
EntityFolder drafts = DB.getInstance(getContext()).folder().getPrimaryFolder(EntityFolder.TYPE_DRAFTS); EntityFolder drafts = DB.getInstance(getContext()).folder().getPrimaryFolder(EntityFolder.TYPE_DRAFTS);
result.putBoolean("drafts" , drafts != null); result.putBoolean("drafts", drafts != null);
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex)); Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
result.putBoolean("drafts" , false); result.putBoolean("drafts", false);
} }
return result; return result;
} }
@ -170,7 +181,7 @@ public class FragmentMessages extends FragmentEx {
@Override @Override
public void onLoadFinished(@NonNull Loader<Bundle> loader, Bundle data) { public void onLoadFinished(@NonNull Loader<Bundle> loader, Bundle data) {
fab.setVisibility(data.getBoolean("drafts" , false) ? View.VISIBLE : View.GONE); fab.setVisibility(data.getBoolean("drafts", false) ? View.VISIBLE : View.GONE);
} }
@Override @Override

@ -114,7 +114,7 @@ public class FragmentSetup extends FragmentEx {
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
String theme = prefs.getString("theme" , "light"); String theme = prefs.getString("theme", "light");
boolean dark = "dark".equals(theme); boolean dark = "dark".equals(theme);
cbDarkTheme.setTag(dark); cbDarkTheme.setTag(dark);
cbDarkTheme.setChecked(dark); cbDarkTheme.setChecked(dark);
@ -124,16 +124,16 @@ public class FragmentSetup extends FragmentEx {
if (checked != (Boolean) button.getTag()) { if (checked != (Boolean) button.getTag()) {
button.setTag(checked); button.setTag(checked);
cbDarkTheme.setChecked(checked); cbDarkTheme.setChecked(checked);
prefs.edit().putString("theme" , checked ? "dark" : "light").apply(); prefs.edit().putString("theme", checked ? "dark" : "light").apply();
} }
} }
}); });
cbDebug.setChecked(prefs.getBoolean("debug" , false)); cbDebug.setChecked(prefs.getBoolean("debug", false));
cbDebug.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { cbDebug.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("debug" , checked).apply(); prefs.edit().putBoolean("debug", checked).apply();
} }
}); });
@ -145,22 +145,6 @@ public class FragmentSetup extends FragmentEx {
tvIdentityDone.setVisibility(View.INVISIBLE); tvIdentityDone.setVisibility(View.INVISIBLE);
tvPermissionsDone.setVisibility(View.INVISIBLE); tvPermissionsDone.setVisibility(View.INVISIBLE);
final DB db = DB.getInstance(getContext());
db.account().liveAccounts(true).observe(this, new Observer<List<EntityAccount>>() {
@Override
public void onChanged(@Nullable List<EntityAccount> accounts) {
tvAccountDone.setVisibility(accounts.size() > 0 ? View.VISIBLE : View.INVISIBLE);
}
});
db.identity().liveIdentities(true).observe(this, new Observer<List<EntityIdentity>>() {
@Override
public void onChanged(@Nullable List<EntityIdentity> identities) {
tvIdentityDone.setVisibility(identities.size() > 0 ? View.VISIBLE : View.INVISIBLE);
}
});
int[] grantResults = new int[permissions.length]; int[] grantResults = new int[permissions.length];
for (int i = 0; i < permissions.length; i++) for (int i = 0; i < permissions.length; i++)
grantResults[i] = ContextCompat.checkSelfPermission(getActivity(), permissions[i]); grantResults[i] = ContextCompat.checkSelfPermission(getActivity(), permissions[i]);
@ -171,6 +155,7 @@ public class FragmentSetup extends FragmentEx {
executor.submit(new Runnable() { executor.submit(new Runnable() {
@Override @Override
public void run() { public void run() {
DB db = DB.getInstance(getContext());
EntityFolder outbox = db.folder().getOutbox(); EntityFolder outbox = db.folder().getOutbox();
if (outbox == null) { if (outbox == null) {
outbox = new EntityFolder(); outbox = new EntityFolder();
@ -186,6 +171,27 @@ public class FragmentSetup extends FragmentEx {
return view; return view;
} }
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
DB db = DB.getInstance(getContext());
db.account().liveAccounts(true).observe(this, new Observer<List<EntityAccount>>() {
@Override
public void onChanged(@Nullable List<EntityAccount> accounts) {
tvAccountDone.setVisibility(accounts.size() > 0 ? View.VISIBLE : View.INVISIBLE);
}
});
db.identity().liveIdentities(true).observe(this, new Observer<List<EntityIdentity>>() {
@Override
public void onChanged(@Nullable List<EntityIdentity> identities) {
tvIdentityDone.setVisibility(identities.size() > 0 ? View.VISIBLE : View.INVISIBLE);
}
});
}
@Override @Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
boolean has = (grantResults.length > 0); boolean has = (grantResults.length > 0);

Loading…
Cancel
Save