Simplification

pull/194/head
M66B 4 years ago
parent 753073cce4
commit 7e13173bdd

@ -42,7 +42,6 @@ import androidx.constraintlayout.widget.Group;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.Observer;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
@ -189,33 +188,11 @@ public class FragmentAccounts extends FragmentBase {
fabCompose.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
Bundle args = new Bundle();
new SimpleTask<EntityFolder>() {
@Override
protected EntityFolder onExecute(Context context, Bundle args) {
return DB.getInstance(context).folder().getPrimaryDrafts();
}
@Override
protected void onExecuted(Bundle args, EntityFolder drafts) {
if (drafts == null)
return;
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext());
lbm.sendBroadcast(
new Intent(ActivityView.ACTION_VIEW_MESSAGES)
.putExtra("account", drafts.account)
.putExtra("folder", drafts.id)
.putExtra("type", drafts.type));
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(getParentFragmentManager(), ex);
}
}.execute(FragmentAccounts.this, args, "account:drafts");
FragmentDialogIdentity.onDrafts(
getContext(),
getViewLifecycleOwner(),
getParentFragmentManager(),
fabCompose, -1L);
return true;
}
});

@ -38,6 +38,7 @@ import androidx.appcompat.app.AlertDialog;
import androidx.constraintlayout.widget.Group;
import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.LifecycleOwner;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.preference.PreferenceManager;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
@ -188,4 +189,50 @@ public class FragmentDialogIdentity extends FragmentDialogBase {
}
}.execute(context, owner, args, "identity:compose");
}
static void onDrafts(Context context, LifecycleOwner owner, FragmentManager manager, FloatingActionButton fabCompose, long account) {
Bundle args = new Bundle();
args.putLong("account", account);
new SimpleTask<EntityFolder>() {
@Override
protected void onPreExecute(Bundle args) {
fabCompose.setEnabled(false);
}
@Override
protected void onPostExecute(Bundle args) {
fabCompose.setEnabled(true);
}
@Override
protected EntityFolder onExecute(Context context, Bundle args) {
long account = args.getLong("account");
DB db = DB.getInstance(context);
if (account < 0)
return db.folder().getPrimaryDrafts();
else
return db.folder().getFolderByType(account, EntityFolder.DRAFTS);
}
@Override
protected void onExecuted(Bundle args, EntityFolder drafts) {
if (drafts == null)
return;
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast(
new Intent(ActivityView.ACTION_VIEW_MESSAGES)
.putExtra("account", drafts.account)
.putExtra("folder", drafts.id)
.putExtra("type", drafts.type));
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(manager, ex);
}
}.execute(context, owner, args, "view:drafts");
}
}

@ -47,7 +47,6 @@ import androidx.constraintlayout.widget.Group;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.Observer;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
@ -211,40 +210,11 @@ public class FragmentFolders extends FragmentBase {
fabCompose.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
Bundle args = new Bundle();
args.putLong("account", account);
new SimpleTask<EntityFolder>() {
@Override
protected EntityFolder onExecute(Context context, Bundle args) {
long account = args.getLong("account");
DB db = DB.getInstance(context);
if (account < 0)
return db.folder().getPrimaryDrafts();
else
return db.folder().getFolderByType(account, EntityFolder.DRAFTS);
}
@Override
protected void onExecuted(Bundle args, EntityFolder drafts) {
if (drafts == null)
return;
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext());
lbm.sendBroadcast(
new Intent(ActivityView.ACTION_VIEW_MESSAGES)
.putExtra("account", drafts.account)
.putExtra("folder", drafts.id)
.putExtra("type", drafts.type));
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(getParentFragmentManager(), ex);
}
}.execute(FragmentFolders.this, args, "folders:drafts");
FragmentDialogIdentity.onDrafts(
getContext(),
getViewLifecycleOwner(),
getParentFragmentManager(),
fabCompose, account);
return true;
}
});

@ -919,40 +919,11 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
fabCompose.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
Bundle args = new Bundle();
args.putLong("account", account);
new SimpleTask<EntityFolder>() {
@Override
protected EntityFolder onExecute(Context context, Bundle args) {
long account = args.getLong("account");
DB db = DB.getInstance(context);
if (account < 0)
return db.folder().getPrimaryDrafts();
else
return db.folder().getFolderByType(account, EntityFolder.DRAFTS);
}
@Override
protected void onExecuted(Bundle args, EntityFolder drafts) {
if (drafts == null)
return;
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext());
lbm.sendBroadcast(
new Intent(ActivityView.ACTION_VIEW_MESSAGES)
.putExtra("account", drafts.account)
.putExtra("folder", drafts.id)
.putExtra("type", drafts.type));
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(getParentFragmentManager(), ex);
}
}.execute(FragmentMessages.this, args, "messages:drafts");
FragmentDialogIdentity.onDrafts(
getContext(),
getViewLifecycleOwner(),
getParentFragmentManager(),
fabCompose, -1L);
return true;
}
});

Loading…
Cancel
Save