Broadcast

This commit is contained in:
Thomas 2024-01-11 17:05:35 +01:00
parent b052547cc4
commit 09a8b6c43c
19 changed files with 659 additions and 451 deletions

View file

@ -79,6 +79,7 @@ import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction; import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.multidex.BuildConfig;
import androidx.navigation.NavController; import androidx.navigation.NavController;
import androidx.navigation.Navigation; import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration; import androidx.navigation.ui.AppBarConfiguration;
@ -220,24 +221,34 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
private final BroadcastReceiver broadcast_error_message = new BroadcastReceiver() { private final BroadcastReceiver broadcast_error_message = new BroadcastReceiver() {
@Override @Override
public void onReceive(android.content.Context context, Intent intent) { public void onReceive(android.content.Context context, Intent intent) {
Bundle b = intent.getExtras(); Bundle args = intent.getExtras();
if (b != null) { if (args != null) {
if (b.getBoolean(Helper.RECEIVE_COMPOSE_ERROR_MESSAGE, false)) { long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1);
String errorMessage = b.getString(Helper.RECEIVE_ERROR_MESSAGE); new CachedBundle(BaseMainActivity.this).getBundle(bundleId, currentAccount, bundle -> {
StatusDraft statusDraft = (StatusDraft) b.getSerializable(Helper.ARG_STATUS_DRAFT); if (bundle.getBoolean(Helper.RECEIVE_COMPOSE_ERROR_MESSAGE, false)) {
Snackbar snackbar = Snackbar.make(binding.getRoot(), errorMessage, 5000); String errorMessage = bundle.getString(Helper.RECEIVE_ERROR_MESSAGE);
View snackbarView = snackbar.getView(); StatusDraft statusDraft = (StatusDraft) bundle.getSerializable(Helper.ARG_STATUS_DRAFT);
TextView textView = snackbarView.findViewById(com.google.android.material.R.id.snackbar_text); Snackbar snackbar = Snackbar.make(binding.getRoot(), errorMessage, 5000);
textView.setMaxLines(5); View snackbarView = snackbar.getView();
snackbar TextView textView = snackbarView.findViewById(com.google.android.material.R.id.snackbar_text);
.setAction(getString(R.string.open_draft), view -> { textView.setMaxLines(5);
Intent intentCompose = new Intent(context, ComposeActivity.class); snackbar
intentCompose.putExtra(Helper.ARG_STATUS_DRAFT, statusDraft); .setAction(getString(R.string.open_draft), view -> {
intentCompose.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Intent intentCompose = new Intent(context, ComposeActivity.class);
context.startActivity(intentCompose); Bundle args2 = new Bundle();
}) args2.putSerializable(Helper.ARG_STATUS_DRAFT, statusDraft);
.show(); new CachedBundle(BaseMainActivity.this).insertBundle(args2, currentAccount, bundleId2 -> {
} Bundle bundle2 = new Bundle();
bundle2.putLong(Helper.ARG_INTENT_ID, bundleId2);
intentCompose.putExtras(bundle2);
intentCompose.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intentCompose);
});
})
.show();
}
});
} }
} }
}; };
@ -246,94 +257,98 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
private final BroadcastReceiver broadcast_data = new BroadcastReceiver() { private final BroadcastReceiver broadcast_data = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
Bundle b = intent.getExtras(); Bundle args = intent.getExtras();
if (b != null) { if (args != null) {
if (b.getBoolean(Helper.RECEIVE_REDRAW_TOPBAR, false)) { long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1);
List<MastodonList> mastodonLists = (List<MastodonList>) b.getSerializable(Helper.RECEIVE_MASTODON_LIST); new CachedBundle(BaseMainActivity.this).getBundle(bundleId, currentAccount, bundle -> {
redrawPinned(mastodonLists); if (bundle.getBoolean(Helper.RECEIVE_REDRAW_TOPBAR, false)) {
} List<MastodonList> mastodonLists = (List<MastodonList>) bundle.getSerializable(Helper.RECEIVE_MASTODON_LIST);
if (b.getBoolean(Helper.RECEIVE_REDRAW_BOTTOM, false)) { redrawPinned(mastodonLists);
bottomMenu = new BottomMenu(BaseMainActivity.this).hydrate(currentAccount, binding.bottomNavView);
if (bottomMenu != null) {
//ManageClick on bottom menu items
if (binding.bottomNavView.findViewById(R.id.nav_home) != null) {
binding.bottomNavView.findViewById(R.id.nav_home).setOnLongClickListener(view -> {
int position = BottomMenu.getPosition(bottomMenu, R.id.nav_home);
if (position >= 0) {
manageFilters(position);
}
return false;
});
}
if (binding.bottomNavView.findViewById(R.id.nav_local) != null) {
binding.bottomNavView.findViewById(R.id.nav_local).setOnLongClickListener(view -> {
int position = BottomMenu.getPosition(bottomMenu, R.id.nav_local);
if (position >= 0) {
manageFilters(position);
}
return false;
});
}
if (binding.bottomNavView.findViewById(R.id.nav_public) != null) {
binding.bottomNavView.findViewById(R.id.nav_public).setOnLongClickListener(view -> {
int position = BottomMenu.getPosition(bottomMenu, R.id.nav_public);
if (position >= 0) {
manageFilters(position);
}
return false;
});
}
binding.bottomNavView.setOnItemSelectedListener(item -> {
int itemId = item.getItemId();
int position = BottomMenu.getPosition(bottomMenu, itemId);
if (position >= 0) {
if (binding.viewPager.getCurrentItem() == position) {
scrollToTop();
} else {
binding.viewPager.setCurrentItem(position, false);
}
}
return true;
});
} }
} else if (b.getBoolean(Helper.RECEIVE_RECREATE_ACTIVITY, false)) { if (bundle.getBoolean(Helper.RECEIVE_REDRAW_BOTTOM, false)) {
recreate(); bottomMenu = new BottomMenu(BaseMainActivity.this).hydrate(currentAccount, binding.bottomNavView);
} else if (b.getBoolean(Helper.RECEIVE_NEW_MESSAGE, false)) { if (bottomMenu != null) {
Status statusSent = (Status) b.getSerializable(Helper.RECEIVE_STATUS_ACTION); //ManageClick on bottom menu items
String statusEditId = b.getString(Helper.ARG_EDIT_STATUS_ID, null); if (binding.bottomNavView.findViewById(R.id.nav_home) != null) {
Snackbar.make(binding.displaySnackBar, getString(R.string.message_has_been_sent), Snackbar.LENGTH_LONG) binding.bottomNavView.findViewById(R.id.nav_home).setOnLongClickListener(view -> {
.setAction(getString(R.string.display), view -> { int position = BottomMenu.getPosition(bottomMenu, R.id.nav_home);
Intent intentContext = new Intent(BaseMainActivity.this, ContextActivity.class); if (position >= 0) {
Bundle args = new Bundle(); manageFilters(position);
args.putSerializable(Helper.ARG_STATUS, statusSent); }
new CachedBundle(BaseMainActivity.this).insertBundle(args, currentAccount, bundleId -> { return false;
Bundle bundle = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
intentContext.putExtras(bundle);
intentContext.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intentContext);
}); });
})
.show();
//The message was edited, we need to update the timeline
if (statusEditId != null) {
//Update message in cache
new Thread(() -> {
StatusCache statusCache = new StatusCache();
statusCache.instance = BaseMainActivity.currentInstance;
statusCache.user_id = BaseMainActivity.currentUserID;
statusCache.status = statusSent;
statusCache.status_id = statusEditId;
try {
new StatusCache(BaseMainActivity.this).updateIfExists(statusCache);
} catch (DBException e) {
e.printStackTrace();
} }
}).start(); if (binding.bottomNavView.findViewById(R.id.nav_local) != null) {
//Update timelines binding.bottomNavView.findViewById(R.id.nav_local).setOnLongClickListener(view -> {
sendAction(context, Helper.ARG_STATUS_UPDATED, statusSent, null); int position = BottomMenu.getPosition(bottomMenu, R.id.nav_local);
if (position >= 0) {
manageFilters(position);
}
return false;
});
}
if (binding.bottomNavView.findViewById(R.id.nav_public) != null) {
binding.bottomNavView.findViewById(R.id.nav_public).setOnLongClickListener(view -> {
int position = BottomMenu.getPosition(bottomMenu, R.id.nav_public);
if (position >= 0) {
manageFilters(position);
}
return false;
});
}
binding.bottomNavView.setOnItemSelectedListener(item -> {
int itemId = item.getItemId();
int position = BottomMenu.getPosition(bottomMenu, itemId);
if (position >= 0) {
if (binding.viewPager.getCurrentItem() == position) {
scrollToTop();
} else {
binding.viewPager.setCurrentItem(position, false);
}
}
return true;
});
}
} else if (bundle.getBoolean(Helper.RECEIVE_RECREATE_ACTIVITY, false)) {
recreate();
} else if (bundle.getBoolean(Helper.RECEIVE_NEW_MESSAGE, false)) {
Status statusSent = (Status) bundle.getSerializable(Helper.RECEIVE_STATUS_ACTION);
String statusEditId = bundle.getString(Helper.ARG_EDIT_STATUS_ID, null);
Snackbar.make(binding.displaySnackBar, getString(R.string.message_has_been_sent), Snackbar.LENGTH_LONG)
.setAction(getString(R.string.display), view -> {
Intent intentContext = new Intent(BaseMainActivity.this, ContextActivity.class);
Bundle args2 = new Bundle();
args2.putSerializable(Helper.ARG_STATUS, statusSent);
new CachedBundle(BaseMainActivity.this).insertBundle(args2, currentAccount, bundleId2 -> {
Bundle bundle2 = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId2);
intentContext.putExtras(bundle2);
intentContext.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intentContext);
});
})
.show();
//The message was edited, we need to update the timeline
if (statusEditId != null) {
//Update message in cache
new Thread(() -> {
StatusCache statusCache = new StatusCache();
statusCache.instance = BaseMainActivity.currentInstance;
statusCache.user_id = BaseMainActivity.currentUserID;
statusCache.status = statusSent;
statusCache.status_id = statusEditId;
try {
new StatusCache(BaseMainActivity.this).updateIfExists(statusCache);
} catch (DBException e) {
e.printStackTrace();
}
}).start();
//Update timelines
sendAction(context, Helper.ARG_STATUS_UPDATED, statusSent, null);
}
} }
} });
} }
} }
}; };
@ -707,12 +722,17 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
} }
viewPager.setCurrentItem(position); viewPager.setCurrentItem(position);
} }
Bundle b = new Bundle(); Bundle args = new Bundle();
b.putBoolean(ARG_REFRESH_NOTFICATION, true); args.putBoolean(ARG_REFRESH_NOTFICATION, true);
Intent intentBC = new Intent(Helper.RECEIVE_STATUS_ACTION); Intent intentBC = new Intent(Helper.RECEIVE_STATUS_ACTION);
intentBC.setPackage(BuildConfig.APPLICATION_ID); intentBC.setPackage(BuildConfig.APPLICATION_ID);
intentBC.putExtras(b); new CachedBundle(activity).insertBundle(args, currentAccount, bundleId -> {
activity.sendBroadcast(intentBC); Bundle bundle = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
intentBC.putExtras(bundle);
activity.sendBroadcast(intentBC);
});
} }
}, 1000); }, 1000);
intent.removeExtra(Helper.INTENT_ACTION); intent.removeExtra(Helper.INTENT_ACTION);

View file

@ -120,26 +120,31 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
private final BroadcastReceiver imageReceiver = new BroadcastReceiver() { private final BroadcastReceiver imageReceiver = new BroadcastReceiver() {
@Override @Override
public void onReceive(android.content.Context context, Intent intent) { public void onReceive(android.content.Context context, Intent intent) {
String imgpath = intent.getStringExtra("imgpath"); Bundle args = intent.getExtras();
float focusX = intent.getFloatExtra("focusX", -2); if (args != null) {
float focusY = intent.getFloatExtra("focusY", -2); long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1);
if (imgpath != null) { new CachedBundle(ComposeActivity.this).getBundle(bundleId, currentAccount, bundle -> {
int position = 0; String imgpath = bundle.getString("imgpath");
for (Status status : statusList) { float focusX = bundle.getFloat("focusX", -2);
if (status.media_attachments != null && status.media_attachments.size() > 0) { float focusY = bundle.getFloat("focusY", -2);
for (Attachment attachment : status.media_attachments) { if (imgpath != null) {
if (attachment.local_path != null && attachment.local_path.equalsIgnoreCase(imgpath)) { int position = 0;
if (focusX != -2) { for (Status status : statusList) {
attachment.focus = focusX + "," + focusY; if (status.media_attachments != null && status.media_attachments.size() > 0) {
for (Attachment attachment : status.media_attachments) {
if (attachment.local_path != null && attachment.local_path.equalsIgnoreCase(imgpath)) {
if (focusX != -2) {
attachment.focus = focusX + "," + focusY;
}
composeAdapter.notifyItemChanged(position);
break;
}
} }
composeAdapter.notifyItemChanged(position);
break;
} }
position++;
} }
} }
position++; });
}
} }
} }
}; };

View file

@ -41,6 +41,7 @@ import app.fedilab.android.activities.MainActivity;
import app.fedilab.android.databinding.ActivityHashtagBinding; import app.fedilab.android.databinding.ActivityHashtagBinding;
import app.fedilab.android.mastodon.client.entities.api.Filter; import app.fedilab.android.mastodon.client.entities.api.Filter;
import app.fedilab.android.mastodon.client.entities.api.Status; import app.fedilab.android.mastodon.client.entities.api.Status;
import app.fedilab.android.mastodon.client.entities.app.CachedBundle;
import app.fedilab.android.mastodon.client.entities.app.Pinned; import app.fedilab.android.mastodon.client.entities.app.Pinned;
import app.fedilab.android.mastodon.client.entities.app.PinnedTimeline; import app.fedilab.android.mastodon.client.entities.app.PinnedTimeline;
import app.fedilab.android.mastodon.client.entities.app.StatusDraft; import app.fedilab.android.mastodon.client.entities.app.StatusDraft;
@ -158,10 +159,14 @@ public class HashTagActivity extends BaseActivity {
List<Status> statuses = new ArrayList<>(); List<Status> statuses = new ArrayList<>();
statuses.add(status); statuses.add(status);
statusDraft.statusDraftList = statuses; statusDraft.statusDraftList = statuses;
Bundle _b = new Bundle(); Bundle args = new Bundle();
_b.putSerializable(Helper.ARG_STATUS_DRAFT, statusDraft); args.putSerializable(Helper.ARG_STATUS_DRAFT, statusDraft);
intentToot.putExtras(_b); new CachedBundle(HashTagActivity.this).insertBundle(args, currentAccount, bundleId -> {
startActivity(intentToot); Bundle bundleCached = new Bundle();
bundleCached.putLong(Helper.ARG_INTENT_ID, bundleId);
intentToot.putExtras(bundleCached);
startActivity(intentToot);
});
}); });
} }
@ -188,13 +193,18 @@ public class HashTagActivity extends BaseActivity {
} }
pinnedTag = false; pinnedTag = false;
invalidateOptionsMenu(); invalidateOptionsMenu();
Bundle b = new Bundle(); Bundle args = new Bundle();
b.putBoolean(Helper.RECEIVE_REDRAW_TOPBAR, true); args.putBoolean(Helper.RECEIVE_REDRAW_TOPBAR, true);
Intent intentBD = new Intent(Helper.BROADCAST_DATA); Intent intentBD = new Intent(Helper.BROADCAST_DATA);
intentBD.putExtras(b); new CachedBundle(HashTagActivity.this).insertBundle(args, currentAccount, bundleId -> {
intentBD.setPackage(BuildConfig.APPLICATION_ID); Bundle bundle = new Bundle();
sendBroadcast(intentBD); bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
dialog.dismiss(); intentBD.putExtras(bundle);
intentBD.setPackage(BuildConfig.APPLICATION_ID);
sendBroadcast(intentBD);
dialog.dismiss();
});
}); });
unpinConfirm.show(); unpinConfirm.show();
} else { } else {
@ -243,12 +253,16 @@ public class HashTagActivity extends BaseActivity {
} else { } else {
new Pinned(HashTagActivity.this).insertPinned(pinned); new Pinned(HashTagActivity.this).insertPinned(pinned);
} }
Bundle b = new Bundle(); Bundle args = new Bundle();
b.putBoolean(Helper.RECEIVE_REDRAW_TOPBAR, true); args.putBoolean(Helper.RECEIVE_REDRAW_TOPBAR, true);
Intent intentBD = new Intent(Helper.BROADCAST_DATA); Intent intentBD = new Intent(Helper.BROADCAST_DATA);
intentBD.putExtras(b); new CachedBundle(HashTagActivity.this).insertBundle(args, currentAccount, bundleId -> {
intentBD.setPackage(BuildConfig.APPLICATION_ID); Bundle bundle = new Bundle();
sendBroadcast(intentBD); bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
intentBD.putExtras(bundle);
intentBD.setPackage(BuildConfig.APPLICATION_ID);
sendBroadcast(intentBD);
});
pinnedTag = true; pinnedTag = true;
invalidateOptionsMenu(); invalidateOptionsMenu();
} catch (DBException e) { } catch (DBException e) {

View file

@ -15,6 +15,8 @@ package app.fedilab.android.mastodon.activities;
* see <http://www.gnu.org/licenses>. */ * see <http://www.gnu.org/licenses>. */
import static app.fedilab.android.BaseMainActivity.currentAccount;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
@ -45,12 +47,12 @@ import java.util.Objects;
import app.fedilab.android.BaseMainActivity; import app.fedilab.android.BaseMainActivity;
import app.fedilab.android.BuildConfig; import app.fedilab.android.BuildConfig;
import app.fedilab.android.R; import app.fedilab.android.R;
import app.fedilab.android.activities.MainActivity;
import app.fedilab.android.databinding.ActivityListBinding; import app.fedilab.android.databinding.ActivityListBinding;
import app.fedilab.android.databinding.PopupAddListBinding; import app.fedilab.android.databinding.PopupAddListBinding;
import app.fedilab.android.databinding.PopupManageAccountsListBinding; import app.fedilab.android.databinding.PopupManageAccountsListBinding;
import app.fedilab.android.mastodon.client.entities.api.Account; import app.fedilab.android.mastodon.client.entities.api.Account;
import app.fedilab.android.mastodon.client.entities.api.MastodonList; import app.fedilab.android.mastodon.client.entities.api.MastodonList;
import app.fedilab.android.mastodon.client.entities.app.CachedBundle;
import app.fedilab.android.mastodon.client.entities.app.Pinned; import app.fedilab.android.mastodon.client.entities.app.Pinned;
import app.fedilab.android.mastodon.client.entities.app.PinnedTimeline; import app.fedilab.android.mastodon.client.entities.app.PinnedTimeline;
import app.fedilab.android.mastodon.client.entities.app.Timeline; import app.fedilab.android.mastodon.client.entities.app.Timeline;
@ -175,7 +177,7 @@ public class MastodonListActivity extends BaseBarActivity implements MastodonLis
timelinesVM.getAccountsInList(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, mastodonList.id, null, null, 0) timelinesVM.getAccountsInList(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, mastodonList.id, null, null, 0)
.observe(MastodonListActivity.this, accounts -> { .observe(MastodonListActivity.this, accounts -> {
if (accounts != null && accounts.size() > 0) { if (accounts != null && accounts.size() > 0) {
accountsVM.muteAccountsHome(MainActivity.currentAccount, accounts); accountsVM.muteAccountsHome(currentAccount, accounts);
} }
}); });
dialog.dismiss(); dialog.dismiss();
@ -307,13 +309,17 @@ public class MastodonListActivity extends BaseBarActivity implements MastodonLis
} else { } else {
binding.notContent.setVisibility(View.GONE); binding.notContent.setVisibility(View.GONE);
} }
Bundle b = new Bundle(); Bundle args = new Bundle();
b.putBoolean(Helper.RECEIVE_REDRAW_TOPBAR, true); args.putBoolean(Helper.RECEIVE_REDRAW_TOPBAR, true);
Intent intentBD = new Intent(Helper.BROADCAST_DATA); Intent intentBD = new Intent(Helper.BROADCAST_DATA);
b.putSerializable(Helper.RECEIVE_MASTODON_LIST, mastodonListList); args.putSerializable(Helper.RECEIVE_MASTODON_LIST, mastodonListList);
intentBD.putExtras(b); new CachedBundle(MastodonListActivity.this).insertBundle(args, currentAccount, bundleId -> {
intentBD.setPackage(BuildConfig.APPLICATION_ID); Bundle bundle = new Bundle();
sendBroadcast(intentBD); bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
intentBD.putExtras(bundle);
intentBD.setPackage(BuildConfig.APPLICATION_ID);
sendBroadcast(intentBD);
});
}); });
alt_bld.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss()); alt_bld.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
AlertDialog alert = alt_bld.create(); AlertDialog alert = alt_bld.create();
@ -343,13 +349,17 @@ public class MastodonListActivity extends BaseBarActivity implements MastodonLis
} else { } else {
Toasty.error(MastodonListActivity.this, getString(R.string.toast_error), Toasty.LENGTH_LONG).show(); Toasty.error(MastodonListActivity.this, getString(R.string.toast_error), Toasty.LENGTH_LONG).show();
} }
Bundle b = new Bundle(); Bundle args = new Bundle();
b.putBoolean(Helper.RECEIVE_REDRAW_TOPBAR, true); args.putBoolean(Helper.RECEIVE_REDRAW_TOPBAR, true);
Intent intentBD = new Intent(Helper.BROADCAST_DATA); Intent intentBD = new Intent(Helper.BROADCAST_DATA);
b.putSerializable(Helper.RECEIVE_MASTODON_LIST, mastodonListList); args.putSerializable(Helper.RECEIVE_MASTODON_LIST, mastodonListList);
intentBD.putExtras(b); new CachedBundle(MastodonListActivity.this).insertBundle(args, currentAccount, bundleId -> {
intentBD.setPackage(BuildConfig.APPLICATION_ID); Bundle bundle = new Bundle();
sendBroadcast(intentBD); bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
intentBD.putExtras(bundle);
intentBD.setPackage(BuildConfig.APPLICATION_ID);
sendBroadcast(intentBD);
});
}); });
dialog.dismiss(); dialog.dismiss();
} else { } else {
@ -392,12 +402,16 @@ public class MastodonListActivity extends BaseBarActivity implements MastodonLis
new Thread(() -> { new Thread(() -> {
try { try {
new Pinned(MastodonListActivity.this).updatePinned(pinned); new Pinned(MastodonListActivity.this).updatePinned(pinned);
Bundle b = new Bundle(); Bundle args = new Bundle();
b.putBoolean(Helper.RECEIVE_REDRAW_TOPBAR, true); args.putBoolean(Helper.RECEIVE_REDRAW_TOPBAR, true);
Intent intentBD = new Intent(Helper.BROADCAST_DATA); Intent intentBD = new Intent(Helper.BROADCAST_DATA);
intentBD.putExtras(b); new CachedBundle(MastodonListActivity.this).insertBundle(args, currentAccount, bundleId -> {
intentBD.setPackage(BuildConfig.APPLICATION_ID); Bundle bundle = new Bundle();
sendBroadcast(intentBD); bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
intentBD.putExtras(bundle);
intentBD.setPackage(BuildConfig.APPLICATION_ID);
sendBroadcast(intentBD);
});
} catch ( } catch (
DBException e) { DBException e) {
e.printStackTrace(); e.printStackTrace();

View file

@ -84,10 +84,10 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload
private final BroadcastReceiver onDownloadComplete = new BroadcastReceiver() { private final BroadcastReceiver onDownloadComplete = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
long id = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1); long id = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);
if (downloadID == id) { if (downloadID == id) {
DownloadManager manager = (DownloadManager) context.getSystemService(DOWNLOAD_SERVICE); DownloadManager manager = (DownloadManager) context.getSystemService(DOWNLOAD_SERVICE);
assert manager != null;
Uri uri = manager.getUriForDownloadedFile(downloadID); Uri uri = manager.getUriForDownloadedFile(downloadID);
Intent shareIntent = new Intent(Intent.ACTION_SEND); Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, uri); shareIntent.putExtra(Intent.EXTRA_STREAM, uri);

View file

@ -135,23 +135,14 @@ public class ProfileActivity extends BaseActivity {
Bundle args = intent.getExtras(); Bundle args = intent.getExtras();
if (args != null) { if (args != null) {
long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1); long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1);
if (bundleId != -1) { new CachedBundle(ProfileActivity.this).getBundle(bundleId, currentAccount, bundle -> {
new CachedBundle(ProfileActivity.this).getBundle(bundleId, currentAccount, bundle -> { Account accountReceived = (Account) bundle.getSerializable(Helper.ARG_ACCOUNT);
Account accountReceived = (Account) bundle.getSerializable(Helper.ARG_ACCOUNT); if (bundle.getBoolean(Helper.RECEIVE_REDRAW_PROFILE, false) && accountReceived != null) {
if (bundle.getBoolean(Helper.RECEIVE_REDRAW_PROFILE, false) && accountReceived != null) {
if (account != null && accountReceived.id != null && account.id != null && accountReceived.id.equalsIgnoreCase(account.id)) {
initializeView(accountReceived);
}
}
});
} else {
Account accountReceived = (Account) args.getSerializable(Helper.ARG_ACCOUNT);
if (args.getBoolean(Helper.RECEIVE_REDRAW_PROFILE, false) && accountReceived != null) {
if (account != null && accountReceived.id != null && account.id != null && accountReceived.id.equalsIgnoreCase(account.id)) { if (account != null && accountReceived.id != null && account.id != null && accountReceived.id.equalsIgnoreCase(account.id)) {
initializeView(accountReceived); initializeView(accountReceived);
} }
} }
} });
} }
} }
}; };
@ -926,12 +917,16 @@ public class ProfileActivity extends BaseActivity {
new Pinned(ProfileActivity.this).insertPinned(finalPinned); new Pinned(ProfileActivity.this).insertPinned(finalPinned);
} }
runOnUiThread(() -> { runOnUiThread(() -> {
Bundle b = new Bundle(); Bundle args = new Bundle();
b.putBoolean(Helper.RECEIVE_REDRAW_TOPBAR, true); args.putBoolean(Helper.RECEIVE_REDRAW_TOPBAR, true);
Intent intentBD = new Intent(Helper.BROADCAST_DATA); Intent intentBD = new Intent(Helper.BROADCAST_DATA);
intentBD.putExtras(b); new CachedBundle(ProfileActivity.this).insertBundle(args, currentAccount, bundleId -> {
intentBD.setPackage(BuildConfig.APPLICATION_ID); Bundle bundle = new Bundle();
sendBroadcast(intentBD); bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
intentBD.putExtras(bundle);
intentBD.setPackage(BuildConfig.APPLICATION_ID);
sendBroadcast(intentBD);
});
}); });
} catch (DBException e) { } catch (DBException e) {
e.printStackTrace(); e.printStackTrace();

View file

@ -15,6 +15,8 @@ package app.fedilab.android.mastodon.activities;
* see <http://www.gnu.org/licenses>. */ * see <http://www.gnu.org/licenses>. */
import static app.fedilab.android.BaseMainActivity.currentAccount;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
@ -48,6 +50,7 @@ import app.fedilab.android.activities.MainActivity;
import app.fedilab.android.databinding.ActivityReorderTabsBinding; import app.fedilab.android.databinding.ActivityReorderTabsBinding;
import app.fedilab.android.databinding.PopupSearchInstanceBinding; import app.fedilab.android.databinding.PopupSearchInstanceBinding;
import app.fedilab.android.mastodon.client.entities.app.BottomMenu; import app.fedilab.android.mastodon.client.entities.app.BottomMenu;
import app.fedilab.android.mastodon.client.entities.app.CachedBundle;
import app.fedilab.android.mastodon.client.entities.app.InstanceSocial; import app.fedilab.android.mastodon.client.entities.app.InstanceSocial;
import app.fedilab.android.mastodon.client.entities.app.Pinned; import app.fedilab.android.mastodon.client.entities.app.Pinned;
import app.fedilab.android.mastodon.client.entities.app.PinnedTimeline; import app.fedilab.android.mastodon.client.entities.app.PinnedTimeline;
@ -284,12 +287,16 @@ public class ReorderTimelinesActivity extends BaseBarActivity implements OnStart
} }
} }
reorderTabAdapter.notifyItemInserted(pinned.pinnedTimelines.size()); reorderTabAdapter.notifyItemInserted(pinned.pinnedTimelines.size());
Bundle b = new Bundle(); Bundle args = new Bundle();
b.putBoolean(Helper.RECEIVE_REDRAW_TOPBAR, true); args.putBoolean(Helper.RECEIVE_REDRAW_TOPBAR, true);
Intent intentBD = new Intent(Helper.BROADCAST_DATA); Intent intentBD = new Intent(Helper.BROADCAST_DATA);
intentBD.putExtras(b); new CachedBundle(ReorderTimelinesActivity.this).insertBundle(args, currentAccount, bundleId -> {
intentBD.setPackage(BuildConfig.APPLICATION_ID); Bundle bundle = new Bundle();
sendBroadcast(intentBD); bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
intentBD.putExtras(bundle);
intentBD.setPackage(BuildConfig.APPLICATION_ID);
sendBroadcast(intentBD);
});
}); });
} else { } else {
runOnUiThread(() -> Toasty.warning(ReorderTimelinesActivity.this, getString(R.string.toast_instance_unavailable), Toast.LENGTH_LONG).show()); runOnUiThread(() -> Toasty.warning(ReorderTimelinesActivity.this, getString(R.string.toast_instance_unavailable), Toast.LENGTH_LONG).show());
@ -373,20 +380,29 @@ public class ReorderTimelinesActivity extends BaseBarActivity implements OnStart
super.onPause(); super.onPause();
if (changes) { if (changes) {
//Update menu //Update menu
Bundle b = new Bundle(); Bundle args = new Bundle();
b.putBoolean(Helper.RECEIVE_REDRAW_TOPBAR, true); args.putBoolean(Helper.RECEIVE_REDRAW_TOPBAR, true);
Intent intentBD = new Intent(Helper.BROADCAST_DATA); Intent intentBD = new Intent(Helper.BROADCAST_DATA);
intentBD.putExtras(b); new CachedBundle(ReorderTimelinesActivity.this).insertBundle(args, currentAccount, bundleId -> {
intentBD.setPackage(BuildConfig.APPLICATION_ID); Bundle bundle = new Bundle();
sendBroadcast(intentBD); bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
intentBD.putExtras(bundle);
intentBD.setPackage(BuildConfig.APPLICATION_ID);
sendBroadcast(intentBD);
});
} }
if (bottomChanges) { if (bottomChanges) {
Bundle b = new Bundle(); Bundle args = new Bundle();
b.putBoolean(Helper.RECEIVE_REDRAW_BOTTOM, true); args.putBoolean(Helper.RECEIVE_REDRAW_BOTTOM, true);
Intent intentBD = new Intent(Helper.BROADCAST_DATA); Intent intentBD = new Intent(Helper.BROADCAST_DATA);
intentBD.putExtras(b); new CachedBundle(ReorderTimelinesActivity.this).insertBundle(args, currentAccount, bundleId -> {
intentBD.setPackage(BuildConfig.APPLICATION_ID); Bundle bundle = new Bundle();
sendBroadcast(intentBD); bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
intentBD.putExtras(bundle);
intentBD.setPackage(BuildConfig.APPLICATION_ID);
sendBroadcast(intentBD);
});
} }
} }

View file

@ -14,6 +14,7 @@ package app.fedilab.android.mastodon.activities.admin;
* You should have received a copy of the GNU General Public License along with Fedilab; if not, * You should have received a copy of the GNU General Public License along with Fedilab; if not,
* see <http://www.gnu.org/licenses>. */ * see <http://www.gnu.org/licenses>. */
import static app.fedilab.android.BaseMainActivity.currentAccount;
import static app.fedilab.android.mastodon.activities.admin.AdminActionActivity.AdminEnum.ACCOUNT; import static app.fedilab.android.mastodon.activities.admin.AdminActionActivity.AdminEnum.ACCOUNT;
import static app.fedilab.android.mastodon.activities.admin.AdminActionActivity.AdminEnum.DOMAIN; import static app.fedilab.android.mastodon.activities.admin.AdminActionActivity.AdminEnum.DOMAIN;
import static app.fedilab.android.mastodon.activities.admin.AdminActionActivity.AdminEnum.REPORT; import static app.fedilab.android.mastodon.activities.admin.AdminActionActivity.AdminEnum.REPORT;
@ -43,6 +44,7 @@ import app.fedilab.android.databinding.PopupAdminFilterAccountsBinding;
import app.fedilab.android.databinding.PopupAdminFilterReportsBinding; import app.fedilab.android.databinding.PopupAdminFilterReportsBinding;
import app.fedilab.android.mastodon.activities.BaseBarActivity; import app.fedilab.android.mastodon.activities.BaseBarActivity;
import app.fedilab.android.mastodon.client.entities.api.admin.AdminDomainBlock; import app.fedilab.android.mastodon.client.entities.api.admin.AdminDomainBlock;
import app.fedilab.android.mastodon.client.entities.app.CachedBundle;
import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.helper.Helper;
import app.fedilab.android.mastodon.helper.ThemeHelper; import app.fedilab.android.mastodon.helper.ThemeHelper;
import app.fedilab.android.mastodon.ui.fragment.admin.FragmentAdminAccount; import app.fedilab.android.mastodon.ui.fragment.admin.FragmentAdminAccount;
@ -63,18 +65,21 @@ public class AdminActionActivity extends BaseBarActivity {
private final BroadcastReceiver mReceiver = new BroadcastReceiver() { private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
Bundle b = intent.getExtras(); Bundle args = intent.getExtras();
if (b != null) { if (args != null) {
AdminDomainBlock adminDomainBlock = (AdminDomainBlock) b.getSerializable(Helper.ARG_ADMIN_DOMAINBLOCK); long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1);
AdminDomainBlock adminDomainBlockDelete = (AdminDomainBlock) b.getSerializable(Helper.ARG_ADMIN_DOMAINBLOCK_DELETE); new CachedBundle(AdminActionActivity.this).getBundle(bundleId, currentAccount, bundle -> {
if (adminDomainBlock != null && adminDomainBlock.domain != null && fragmentAdminDomain != null) { AdminDomainBlock adminDomainBlock = (AdminDomainBlock) bundle.getSerializable(Helper.ARG_ADMIN_DOMAINBLOCK);
fragmentAdminDomain.update(adminDomainBlock); AdminDomainBlock adminDomainBlockDelete = (AdminDomainBlock) bundle.getSerializable(Helper.ARG_ADMIN_DOMAINBLOCK_DELETE);
} if (adminDomainBlock != null && adminDomainBlock.domain != null && fragmentAdminDomain != null) {
if (adminDomainBlockDelete != null && fragmentAdminDomain != null) { fragmentAdminDomain.update(adminDomainBlock);
fragmentAdminDomain.delete(adminDomainBlockDelete); }
} if (adminDomainBlockDelete != null && fragmentAdminDomain != null) {
} fragmentAdminDomain.delete(adminDomainBlockDelete);
}
});
}
} }
}; };

View file

@ -15,6 +15,8 @@ package app.fedilab.android.mastodon.activities.admin;
* see <http://www.gnu.org/licenses>. */ * see <http://www.gnu.org/licenses>. */
import static app.fedilab.android.BaseMainActivity.currentAccount;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.view.Menu; import android.view.Menu;
@ -37,6 +39,7 @@ import app.fedilab.android.activities.MainActivity;
import app.fedilab.android.databinding.ActivityAdminDomainblockBinding; import app.fedilab.android.databinding.ActivityAdminDomainblockBinding;
import app.fedilab.android.mastodon.activities.BaseBarActivity; import app.fedilab.android.mastodon.activities.BaseBarActivity;
import app.fedilab.android.mastodon.client.entities.api.admin.AdminDomainBlock; import app.fedilab.android.mastodon.client.entities.api.admin.AdminDomainBlock;
import app.fedilab.android.mastodon.client.entities.app.CachedBundle;
import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.helper.Helper;
import app.fedilab.android.mastodon.viewmodel.mastodon.AdminVM; import app.fedilab.android.mastodon.viewmodel.mastodon.AdminVM;
import es.dmoral.toasty.Toasty; import es.dmoral.toasty.Toasty;
@ -109,10 +112,17 @@ public class AdminDomainBlockActivity extends BaseBarActivity {
} else { } else {
Toasty.error(AdminDomainBlockActivity.this, getString(R.string.toast_error), Toasty.LENGTH_SHORT).show(); Toasty.error(AdminDomainBlockActivity.this, getString(R.string.toast_error), Toasty.LENGTH_SHORT).show();
} }
Intent intent = new Intent(Helper.BROADCAST_DATA).putExtra(Helper.ARG_ADMIN_DOMAINBLOCK, adminDomainBlockResult); Intent intent = new Intent(Helper.BROADCAST_DATA);
intent.setPackage(BuildConfig.APPLICATION_ID); Bundle args = new Bundle();
sendBroadcast(intent); args.putSerializable(Helper.ARG_ADMIN_DOMAINBLOCK, adminDomainBlockResult);
finish(); new CachedBundle(AdminDomainBlockActivity.this).insertBundle(args, currentAccount, bundleId -> {
Bundle bundle = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
intent.putExtras(bundle);
intent.setPackage(BuildConfig.APPLICATION_ID);
sendBroadcast(intent);
finish();
});
} }
); );
}); });
@ -138,10 +148,18 @@ public class AdminDomainBlockActivity extends BaseBarActivity {
.setPositiveButton(R.string.unblock_domain, (dialog, which) -> { .setPositiveButton(R.string.unblock_domain, (dialog, which) -> {
adminVM.deleteDomain(MainActivity.currentInstance, MainActivity.currentToken, adminDomainBlock.id) adminVM.deleteDomain(MainActivity.currentInstance, MainActivity.currentToken, adminDomainBlock.id)
.observe(AdminDomainBlockActivity.this, adminDomainBlockResult -> { .observe(AdminDomainBlockActivity.this, adminDomainBlockResult -> {
Intent intent = new Intent(Helper.BROADCAST_DATA).putExtra(Helper.ARG_ADMIN_DOMAINBLOCK_DELETE, adminDomainBlock); Intent intent = new Intent(Helper.BROADCAST_DATA);
intent.setPackage(BuildConfig.APPLICATION_ID); Bundle args = new Bundle();
sendBroadcast(intent); args.putSerializable(Helper.ARG_ADMIN_DOMAINBLOCK_DELETE, adminDomainBlock);
finish(); new CachedBundle(AdminDomainBlockActivity.this).insertBundle(args, currentAccount, bundleId -> {
Bundle bundle = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
intent.putExtras(bundle);
intent.setPackage(BuildConfig.APPLICATION_ID);
sendBroadcast(intent);
finish();
});
} }
); );
dialog.dismiss(); dialog.dismiss();

View file

@ -872,13 +872,17 @@ public class Helper {
*/ */
public static void sendToastMessage(Context context, String type, String content) { public static void sendToastMessage(Context context, String type, String content) {
Intent intentBC = new Intent(context, ToastMessage.class); Intent intentBC = new Intent(context, ToastMessage.class);
Bundle b = new Bundle(); Bundle args = new Bundle();
b.putString(RECEIVE_TOAST_TYPE, type); args.putString(RECEIVE_TOAST_TYPE, type);
b.putString(RECEIVE_TOAST_CONTENT, content); args.putString(RECEIVE_TOAST_CONTENT, content);
intentBC.setAction(Helper.RECEIVE_TOAST_MESSAGE); intentBC.setAction(Helper.RECEIVE_TOAST_MESSAGE);
intentBC.putExtras(b); new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> {
intentBC.setPackage(BuildConfig.APPLICATION_ID); Bundle bundle = new Bundle();
context.sendBroadcast(intentBC); bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
intentBC.putExtras(bundle);
intentBC.setPackage(BuildConfig.APPLICATION_ID);
context.sendBroadcast(intentBC);
});
} }
/** /**
@ -1514,12 +1518,16 @@ public class Helper {
* @param activity - Activity * @param activity - Activity
*/ */
public static void recreateMainActivity(Activity activity) { public static void recreateMainActivity(Activity activity) {
Bundle b = new Bundle(); Bundle args = new Bundle();
b.putBoolean(Helper.RECEIVE_RECREATE_ACTIVITY, true); args.putBoolean(Helper.RECEIVE_RECREATE_ACTIVITY, true);
Intent intentBD = new Intent(Helper.BROADCAST_DATA); Intent intentBD = new Intent(Helper.BROADCAST_DATA);
intentBD.putExtras(b); new CachedBundle(activity).insertBundle(args, currentAccount, bundleId -> {
intentBD.setPackage(BuildConfig.APPLICATION_ID); Bundle bundle = new Bundle();
activity.sendBroadcast(intentBD); bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
intentBD.putExtras(bundle);
intentBD.setPackage(BuildConfig.APPLICATION_ID);
activity.sendBroadcast(intentBD);
});
} }
public static void showKeyboard(Context context, View view) { public static void showKeyboard(Context context, View view) {

View file

@ -1,6 +1,8 @@
package app.fedilab.android.mastodon.imageeditor; package app.fedilab.android.mastodon.imageeditor;
import static app.fedilab.android.BaseMainActivity.currentAccount;
import android.Manifest; import android.Manifest;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
@ -41,6 +43,7 @@ import java.io.InputStream;
import app.fedilab.android.BuildConfig; import app.fedilab.android.BuildConfig;
import app.fedilab.android.R; import app.fedilab.android.R;
import app.fedilab.android.databinding.ActivityEditImageBinding; import app.fedilab.android.databinding.ActivityEditImageBinding;
import app.fedilab.android.mastodon.client.entities.app.CachedBundle;
import app.fedilab.android.mastodon.helper.CirclesDrawingView; import app.fedilab.android.mastodon.helper.CirclesDrawingView;
import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.helper.Helper;
import app.fedilab.android.mastodon.imageeditor.base.BaseActivity; import app.fedilab.android.mastodon.imageeditor.base.BaseActivity;
@ -283,7 +286,8 @@ public class EditImageActivity extends BaseActivity implements OnPhotoEditorList
binding.photoEditorView.getSource().setImageURI(Uri.fromFile(new File(imagePath))); binding.photoEditorView.getSource().setImageURI(Uri.fromFile(new File(imagePath)));
if (exit) { if (exit) {
Intent intentImage = new Intent(Helper.INTENT_SEND_MODIFIED_IMAGE); Intent intentImage = new Intent(Helper.INTENT_SEND_MODIFIED_IMAGE);
intentImage.putExtra("imgpath", imagePath); Bundle args = new Bundle();
args.putString("imgpath", imagePath);
CirclesDrawingView.CircleArea circleArea = binding.focusCircle.getTouchedCircle(); CirclesDrawingView.CircleArea circleArea = binding.focusCircle.getTouchedCircle();
if (circleArea != null) { if (circleArea != null) {
//Dimension of the editor containing the image //Dimension of the editor containing the image
@ -323,13 +327,16 @@ public class EditImageActivity extends BaseActivity implements OnPhotoEditorList
} else if (focusY < -1) { } else if (focusY < -1) {
focusY = -1; focusY = -1;
} }
intentImage.putExtra("focusX", focusX); args.putFloat("focusX", focusX);
intentImage.putExtra("focusY", focusY); args.putFloat("focusY", focusY);
} }
intentImage.setPackage(BuildConfig.APPLICATION_ID); new CachedBundle(EditImageActivity.this).insertBundle(args, currentAccount, bundleId -> {
sendBroadcast(intentImage); intentImage.putExtras(args);
finish(); intentImage.setPackage(BuildConfig.APPLICATION_ID);
sendBroadcast(intentImage);
finish();
});
} }
} }

View file

@ -60,6 +60,7 @@ import app.fedilab.android.mastodon.client.entities.api.ScheduledStatus;
import app.fedilab.android.mastodon.client.entities.api.Status; import app.fedilab.android.mastodon.client.entities.api.Status;
import app.fedilab.android.mastodon.client.entities.app.Account; import app.fedilab.android.mastodon.client.entities.app.Account;
import app.fedilab.android.mastodon.client.entities.app.BaseAccount; import app.fedilab.android.mastodon.client.entities.app.BaseAccount;
import app.fedilab.android.mastodon.client.entities.app.CachedBundle;
import app.fedilab.android.mastodon.client.entities.app.CamelTag; import app.fedilab.android.mastodon.client.entities.app.CamelTag;
import app.fedilab.android.mastodon.client.entities.app.PostState; import app.fedilab.android.mastodon.client.entities.app.PostState;
import app.fedilab.android.mastodon.client.entities.app.StatusDraft; import app.fedilab.android.mastodon.client.entities.app.StatusDraft;
@ -223,14 +224,24 @@ public class ComposeWorker extends Worker {
} }
Call<Status> statusCall; Call<Status> statusCall;
if (error) { if (error) {
Bundle b = new Bundle(); Bundle args = new Bundle();
b.putBoolean(Helper.RECEIVE_COMPOSE_ERROR_MESSAGE, true); args.putBoolean(Helper.RECEIVE_COMPOSE_ERROR_MESSAGE, true);
Intent intentBD = new Intent(Helper.INTENT_COMPOSE_ERROR_MESSAGE); Intent intentBD = new Intent(Helper.INTENT_COMPOSE_ERROR_MESSAGE);
b.putSerializable(Helper.RECEIVE_ERROR_MESSAGE, context.getString(R.string.media_cannot_be_uploaded)); args.putSerializable(Helper.RECEIVE_ERROR_MESSAGE, context.getString(R.string.media_cannot_be_uploaded));
b.putSerializable(Helper.ARG_STATUS_DRAFT, dataPost.statusDraft); args.putSerializable(Helper.ARG_STATUS_DRAFT, dataPost.statusDraft);
intentBD.putExtras(b); BaseAccount account = null;
intentBD.setPackage(BuildConfig.APPLICATION_ID); try {
context.sendBroadcast(intentBD); account = new Account(context).getAccountByToken(dataPost.token);
} catch (DBException e) {
e.printStackTrace();
}
new CachedBundle(context).insertBundle(args, account, bundleId -> {
Bundle bundle = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
intentBD.putExtras(bundle);
intentBD.setPackage(BuildConfig.APPLICATION_ID);
context.sendBroadcast(intentBD);
});
return; return;
} }
if (statuses.get(i).local_only) { if (statuses.get(i).local_only) {
@ -304,30 +315,51 @@ public class ComposeWorker extends Worker {
} }
} }
} else if (statusResponse.errorBody() != null) { } else if (statusResponse.errorBody() != null) {
Bundle b = new Bundle(); Bundle args = new Bundle();
b.putBoolean(Helper.RECEIVE_COMPOSE_ERROR_MESSAGE, true); args.putBoolean(Helper.RECEIVE_COMPOSE_ERROR_MESSAGE, true);
Intent intentBD = new Intent(Helper.INTENT_COMPOSE_ERROR_MESSAGE); Intent intentBD = new Intent(Helper.INTENT_COMPOSE_ERROR_MESSAGE);
b.putSerializable(Helper.ARG_STATUS_DRAFT, dataPost.statusDraft); args.putSerializable(Helper.ARG_STATUS_DRAFT, dataPost.statusDraft);
String err = statusResponse.errorBody().string(); String err = statusResponse.errorBody().string();
if (err.contains("{\"error\":\"")) { if (err.contains("{\"error\":\"")) {
err = err.replaceAll("\\{\"error\":\"(.*)\"\\}", "$1"); err = err.replaceAll("\\{\"error\":\"(.*)\"\\}", "$1");
} }
b.putSerializable(Helper.RECEIVE_ERROR_MESSAGE, err); args.putSerializable(Helper.RECEIVE_ERROR_MESSAGE, err);
intentBD.putExtras(b);
intentBD.setPackage(BuildConfig.APPLICATION_ID); BaseAccount account = null;
context.sendBroadcast(intentBD); try {
account = new Account(context).getAccountByToken(dataPost.token);
} catch (DBException e) {
e.printStackTrace();
}
new CachedBundle(context).insertBundle(args, account, bundleId -> {
Bundle bundle = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
intentBD.putExtras(bundle);
intentBD.setPackage(BuildConfig.APPLICATION_ID);
context.sendBroadcast(intentBD);
});
return; return;
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
Bundle b = new Bundle(); Bundle args = new Bundle();
b.putBoolean(Helper.RECEIVE_COMPOSE_ERROR_MESSAGE, true); args.putBoolean(Helper.RECEIVE_COMPOSE_ERROR_MESSAGE, true);
b.putSerializable(Helper.ARG_STATUS_DRAFT, dataPost.statusDraft); args.putSerializable(Helper.ARG_STATUS_DRAFT, dataPost.statusDraft);
Intent intentBD = new Intent(Helper.INTENT_COMPOSE_ERROR_MESSAGE); Intent intentBD = new Intent(Helper.INTENT_COMPOSE_ERROR_MESSAGE);
b.putSerializable(Helper.RECEIVE_ERROR_MESSAGE, e.getMessage()); args.putSerializable(Helper.RECEIVE_ERROR_MESSAGE, e.getMessage());
intentBD.putExtras(b); BaseAccount account = null;
intentBD.setPackage(BuildConfig.APPLICATION_ID); try {
context.sendBroadcast(intentBD); account = new Account(context).getAccountByToken(dataPost.token);
} catch (DBException e2) {
e2.printStackTrace();
}
new CachedBundle(context).insertBundle(args, account, bundleId -> {
Bundle bundle = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
intentBD.putExtras(bundle);
intentBD.setPackage(BuildConfig.APPLICATION_ID);
context.sendBroadcast(intentBD);
});
return; return;
} }
} else { } else {
@ -375,14 +407,24 @@ public class ComposeWorker extends Worker {
} }
if (dataPost.scheduledDate == null && dataPost.token != null && firstSendMessage != null) { if (dataPost.scheduledDate == null && dataPost.token != null && firstSendMessage != null) {
Bundle b = new Bundle(); Bundle args = new Bundle();
b.putBoolean(Helper.RECEIVE_NEW_MESSAGE, true); args.putBoolean(Helper.RECEIVE_NEW_MESSAGE, true);
b.putString(Helper.ARG_EDIT_STATUS_ID, dataPost.statusEditId); args.putString(Helper.ARG_EDIT_STATUS_ID, dataPost.statusEditId);
Intent intentBD = new Intent(Helper.BROADCAST_DATA); Intent intentBD = new Intent(Helper.BROADCAST_DATA);
b.putSerializable(Helper.RECEIVE_STATUS_ACTION, firstSendMessage); args.putSerializable(Helper.RECEIVE_STATUS_ACTION, firstSendMessage);
intentBD.putExtras(b); BaseAccount account = null;
intentBD.setPackage(BuildConfig.APPLICATION_ID); try {
context.sendBroadcast(intentBD); account = new Account(context).getAccountByToken(dataPost.token);
} catch (DBException e2) {
e2.printStackTrace();
}
new CachedBundle(context).insertBundle(args, account, bundleId -> {
Bundle bundle = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
intentBD.putExtras(bundle);
intentBD.setPackage(BuildConfig.APPLICATION_ID);
context.sendBroadcast(intentBD);
});
} }
} }

View file

@ -2171,9 +2171,15 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
} }
statusDeleted.id = null; statusDeleted.id = null;
statusDraft.statusDraftList.add(statusDeleted); statusDraft.statusDraftList.add(statusDeleted);
intent.putExtra(Helper.ARG_STATUS_DRAFT, statusDraft); Bundle args = new Bundle();
intent.putExtra(Helper.ARG_STATUS_REPLY_ID, statusDeleted.in_reply_to_id); args.putSerializable(Helper.ARG_STATUS_DRAFT, statusDraft);
context.startActivity(intent); args.putSerializable(Helper.ARG_STATUS_REPLY_ID, statusDeleted.in_reply_to_id);
new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> {
Bundle bundle = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
intent.putExtras(bundle);
context.startActivity(intent);
});
sendAction(context, Helper.ARG_STATUS_DELETED, statusToDeal, null); sendAction(context, Helper.ARG_STATUS_DELETED, statusToDeal, null);
}); });
} }
@ -2194,10 +2200,16 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
statusToDeal.spoilerChecked = true; statusToDeal.spoilerChecked = true;
} }
statusDraft.statusDraftList.add(statusToDeal); statusDraft.statusDraftList.add(statusToDeal);
intent.putExtra(Helper.ARG_STATUS_DRAFT, statusDraft); Bundle args = new Bundle();
intent.putExtra(Helper.ARG_EDIT_STATUS_ID, statusToDeal.id); args.putSerializable(Helper.ARG_STATUS_DRAFT, statusDraft);
intent.putExtra(Helper.ARG_STATUS_REPLY_ID, statusToDeal.in_reply_to_id); args.putString(Helper.ARG_EDIT_STATUS_ID, statusToDeal.id);
context.startActivity(intent); args.putString(Helper.ARG_STATUS_REPLY_ID, statusToDeal.in_reply_to_id);
new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> {
Bundle bundle = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
intent.putExtras(bundle);
context.startActivity(intent);
});
} else { } else {
Toasty.error(context, context.getString(R.string.toast_error), Toasty.LENGTH_SHORT).show(); Toasty.error(context, context.getString(R.string.toast_error), Toasty.LENGTH_SHORT).show();
} }
@ -2372,10 +2384,14 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
}); });
} else if (itemId == R.id.action_mention) { } else if (itemId == R.id.action_mention) {
Intent intent = new Intent(context, ComposeActivity.class); Intent intent = new Intent(context, ComposeActivity.class);
Bundle b = new Bundle(); Bundle args = new Bundle();
b.putSerializable(Helper.ARG_STATUS_MENTION, statusToDeal); args.putSerializable(Helper.ARG_STATUS_MENTION, statusToDeal);
intent.putExtras(b); new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> {
context.startActivity(intent); Bundle bundle = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
intent.putExtras(bundle);
context.startActivity(intent);
});
} else if (itemId == R.id.action_open_with) { } else if (itemId == R.id.action_open_with) {
new Thread(() -> { new Thread(() -> {
try { try {
@ -2475,19 +2491,31 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
if (results != null && results.statuses != null && results.statuses.size() > 0) { if (results != null && results.statuses != null && results.statuses.size() > 0) {
Status fetchedStatus = results.statuses.get(0); Status fetchedStatus = results.statuses.get(0);
Intent intent = new Intent(context, ComposeActivity.class); Intent intent = new Intent(context, ComposeActivity.class);
intent.putExtra(Helper.ARG_STATUS_REPLY, fetchedStatus); Bundle args = new Bundle();
context.startActivity(intent); args.putSerializable(Helper.ARG_STATUS_REPLY, fetchedStatus);
new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> {
Bundle bundle = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
intent.putExtras(bundle);
context.startActivity(intent);
});
} else { } else {
Toasty.info(context, context.getString(R.string.toast_error_search), Toasty.LENGTH_SHORT).show(); Toasty.info(context, context.getString(R.string.toast_error_search), Toasty.LENGTH_SHORT).show();
} }
}); });
} else { } else {
Intent intent = new Intent(context, ComposeActivity.class); Intent intent = new Intent(context, ComposeActivity.class);
intent.putExtra(Helper.ARG_STATUS_REPLY, statusToDeal); Bundle args = new Bundle();
args.putSerializable(Helper.ARG_STATUS_REPLY, statusToDeal);
if (status.reblog != null) { if (status.reblog != null) {
intent.putExtra(Helper.ARG_MENTION_BOOSTER, status.account); args.putSerializable(Helper.ARG_MENTION_BOOSTER, status.account);
} }
context.startActivity(intent); new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> {
Bundle bundle = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
intent.putExtras(bundle);
context.startActivity(intent);
});
} }
}); });
//For reports //For reports
@ -2811,20 +2839,24 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
* @param id - Id of an account (can be null) * @param id - Id of an account (can be null)
*/ */
public static void sendAction(@NonNull Context context, @NonNull String type, @Nullable Status status, @Nullable String id) { public static void sendAction(@NonNull Context context, @NonNull String type, @Nullable Status status, @Nullable String id) {
Bundle b = new Bundle(); Bundle args = new Bundle();
if (status != null) { if (status != null) {
b.putSerializable(type, status); args.putSerializable(type, status);
} }
if (id != null) { if (id != null) {
b.putString(type, id); args.putString(type, id);
} }
if (type.equals(ARG_TIMELINE_REFRESH_ALL)) { if (type.equals(ARG_TIMELINE_REFRESH_ALL)) {
b.putBoolean(ARG_TIMELINE_REFRESH_ALL, true); args.putBoolean(ARG_TIMELINE_REFRESH_ALL, true);
} }
Intent intentBC = new Intent(Helper.RECEIVE_STATUS_ACTION); Intent intentBC = new Intent(Helper.RECEIVE_STATUS_ACTION);
intentBC.putExtras(b); new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> {
intentBC.setPackage(BuildConfig.APPLICATION_ID); Bundle bundle = new Bundle();
context.sendBroadcast(intentBC); bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
intentBC.putExtras(bundle);
intentBC.setPackage(BuildConfig.APPLICATION_ID);
context.sendBroadcast(intentBC);
});
} }

View file

@ -15,9 +15,12 @@ package app.fedilab.android.mastodon.ui.drawer;
* see <http://www.gnu.org/licenses>. */ * see <http://www.gnu.org/licenses>. */
import static app.fedilab.android.BaseMainActivity.currentAccount;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -39,6 +42,7 @@ import app.fedilab.android.databinding.DrawerStatusDraftBinding;
import app.fedilab.android.mastodon.activities.ComposeActivity; import app.fedilab.android.mastodon.activities.ComposeActivity;
import app.fedilab.android.mastodon.client.entities.api.Attachment; import app.fedilab.android.mastodon.client.entities.api.Attachment;
import app.fedilab.android.mastodon.client.entities.api.Status; import app.fedilab.android.mastodon.client.entities.api.Status;
import app.fedilab.android.mastodon.client.entities.app.CachedBundle;
import app.fedilab.android.mastodon.client.entities.app.StatusDraft; import app.fedilab.android.mastodon.client.entities.app.StatusDraft;
import app.fedilab.android.mastodon.exception.DBException; import app.fedilab.android.mastodon.exception.DBException;
import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.helper.Helper;
@ -100,11 +104,16 @@ public class StatusDraftAdapter extends RecyclerView.Adapter<StatusDraftAdapter.
holder.binding.cardviewContainer.setOnClickListener(v -> { holder.binding.cardviewContainer.setOnClickListener(v -> {
Intent intent = new Intent(context, ComposeActivity.class); Intent intent = new Intent(context, ComposeActivity.class);
intent.putExtra(Helper.ARG_STATUS_DRAFT, statusDraft); Bundle args = new Bundle();
context.startActivity(intent); args.putSerializable(Helper.ARG_STATUS_DRAFT, statusDraft);
new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> {
Bundle bundle = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
intent.putExtras(bundle);
context.startActivity(intent);
});
}); });
holder.binding.delete.setOnClickListener(v -> { holder.binding.delete.setOnClickListener(v -> {
AlertDialog.Builder unfollowConfirm = new MaterialAlertDialogBuilder(context); AlertDialog.Builder unfollowConfirm = new MaterialAlertDialogBuilder(context);
unfollowConfirm.setMessage(context.getString(R.string.remove_draft)); unfollowConfirm.setMessage(context.getString(R.string.remove_draft));

View file

@ -16,10 +16,12 @@ package app.fedilab.android.mastodon.ui.drawer;
import static androidx.core.text.HtmlCompat.FROM_HTML_MODE_LEGACY; import static androidx.core.text.HtmlCompat.FROM_HTML_MODE_LEGACY;
import static app.fedilab.android.BaseMainActivity.currentAccount;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Build; import android.os.Build;
import android.os.Bundle;
import android.text.Html; import android.text.Html;
import android.text.SpannableString; import android.text.SpannableString;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -44,6 +46,7 @@ import app.fedilab.android.R;
import app.fedilab.android.databinding.DrawerStatusScheduledBinding; import app.fedilab.android.databinding.DrawerStatusScheduledBinding;
import app.fedilab.android.mastodon.activities.ComposeActivity; import app.fedilab.android.mastodon.activities.ComposeActivity;
import app.fedilab.android.mastodon.client.entities.api.ScheduledStatus; import app.fedilab.android.mastodon.client.entities.api.ScheduledStatus;
import app.fedilab.android.mastodon.client.entities.app.CachedBundle;
import app.fedilab.android.mastodon.client.entities.app.ScheduledBoost; import app.fedilab.android.mastodon.client.entities.app.ScheduledBoost;
import app.fedilab.android.mastodon.client.entities.app.StatusDraft; import app.fedilab.android.mastodon.client.entities.app.StatusDraft;
import app.fedilab.android.mastodon.exception.DBException; import app.fedilab.android.mastodon.exception.DBException;
@ -126,10 +129,15 @@ public class StatusScheduledAdapter extends RecyclerView.Adapter<StatusScheduled
holder.binding.cardviewContainer.setOnClickListener(v -> { holder.binding.cardviewContainer.setOnClickListener(v -> {
if (statusDraft != null) { if (statusDraft != null) {
Intent intent = new Intent(context, ComposeActivity.class); Intent intent = new Intent(context, ComposeActivity.class);
intent.putExtra(Helper.ARG_STATUS_DRAFT, statusDraft); Bundle args = new Bundle();
context.startActivity(intent); args.putSerializable(Helper.ARG_STATUS_DRAFT, statusDraft);
new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> {
Bundle bundle = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
intent.putExtras(bundle);
context.startActivity(intent);
});
} }
}); });
holder.binding.delete.setOnClickListener(v -> { holder.binding.delete.setOnClickListener(v -> {
AlertDialog.Builder unfollowConfirm = new MaterialAlertDialogBuilder(context); AlertDialog.Builder unfollowConfirm = new MaterialAlertDialogBuilder(context);

View file

@ -63,67 +63,71 @@ public class FragmentMastodonContext extends Fragment {
private final BroadcastReceiver receive_action = new BroadcastReceiver() { private final BroadcastReceiver receive_action = new BroadcastReceiver() {
@Override @Override
public void onReceive(android.content.Context context, Intent intent) { public void onReceive(android.content.Context context, Intent intent) {
Bundle b = intent.getExtras(); Bundle args = intent.getExtras();
if (b != null) { if (args != null) {
Status receivedStatus = (Status) b.getSerializable(Helper.ARG_STATUS_ACTION); long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1);
String delete_statuses_for_user = b.getString(Helper.ARG_STATUS_ACCOUNT_ID_DELETED); new CachedBundle(requireActivity()).getBundle(bundleId, currentAccount, bundle -> {
Status status_to_delete = (Status) b.getSerializable(Helper.ARG_STATUS_DELETED); Status receivedStatus = (Status) bundle.getSerializable(Helper.ARG_STATUS_ACTION);
Status statusPosted = (Status) b.getSerializable(Helper.ARG_STATUS_POSTED); String delete_statuses_for_user = bundle.getString(Helper.ARG_STATUS_ACCOUNT_ID_DELETED);
Status status_to_update = (Status) b.getSerializable(Helper.ARG_STATUS_UPDATED); Status status_to_delete = (Status) bundle.getSerializable(Helper.ARG_STATUS_DELETED);
if (receivedStatus != null && statusAdapter != null) { Status statusPosted = (Status) bundle.getSerializable(Helper.ARG_STATUS_POSTED);
int position = getPosition(receivedStatus); Status status_to_update = (Status) bundle.getSerializable(Helper.ARG_STATUS_UPDATED);
if (position >= 0) { if (receivedStatus != null && statusAdapter != null) {
statuses.get(position).reblog = receivedStatus.reblog; int position = getPosition(receivedStatus);
statuses.get(position).reblogged = receivedStatus.reblogged; if (position >= 0) {
statuses.get(position).favourited = receivedStatus.favourited; statuses.get(position).reblog = receivedStatus.reblog;
statuses.get(position).bookmarked = receivedStatus.bookmarked; statuses.get(position).reblogged = receivedStatus.reblogged;
statuses.get(position).reblogs_count = receivedStatus.reblogs_count; statuses.get(position).favourited = receivedStatus.favourited;
statuses.get(position).favourites_count = receivedStatus.favourites_count; statuses.get(position).bookmarked = receivedStatus.bookmarked;
statusAdapter.notifyItemChanged(position); statuses.get(position).reblogs_count = receivedStatus.reblogs_count;
} statuses.get(position).favourites_count = receivedStatus.favourites_count;
} else if (delete_statuses_for_user != null && statusAdapter != null) { statusAdapter.notifyItemChanged(position);
List<Status> statusesToRemove = new ArrayList<>();
for (Status status : statuses) {
if (status.account.id.equals(delete_statuses_for_user)) {
statusesToRemove.add(status);
} }
} } else if (delete_statuses_for_user != null && statusAdapter != null) {
for (Status statusToRemove : statusesToRemove) { List<Status> statusesToRemove = new ArrayList<>();
int position = getPosition(statusToRemove); for (Status status : statuses) {
if (status.account.id.equals(delete_statuses_for_user)) {
statusesToRemove.add(status);
}
}
for (Status statusToRemove : statusesToRemove) {
int position = getPosition(statusToRemove);
if (position >= 0) {
statuses.remove(position);
statusAdapter.notifyItemRemoved(position);
}
}
} else if (status_to_delete != null && statusAdapter != null) {
int position = getPosition(status_to_delete);
if (position >= 0) { if (position >= 0) {
statuses.remove(position); statuses.remove(position);
statusAdapter.notifyItemRemoved(position); statusAdapter.notifyItemRemoved(position);
} }
} } else if (status_to_update != null && statusAdapter != null) {
} else if (status_to_delete != null && statusAdapter != null) { int position = getPosition(status_to_update);
int position = getPosition(status_to_delete); if (position >= 0) {
if (position >= 0) { statuses.set(position, status_to_update);
statuses.remove(position); statusAdapter.notifyItemChanged(position);
statusAdapter.notifyItemRemoved(position); }
} } else if (statusPosted != null && statusAdapter != null) {
} else if (status_to_update != null && statusAdapter != null) { if (requireActivity() instanceof ContextActivity) {
int position = getPosition(status_to_update); int i = 0;
if (position >= 0) { for (Status status : statuses) {
statuses.set(position, status_to_update); if (status.id.equals(statusPosted.in_reply_to_id)) {
statusAdapter.notifyItemChanged(position); statuses.add((i + 1), statusPosted);
} statusAdapter.notifyItemInserted((i + 1));
} else if (statusPosted != null && statusAdapter != null) { if (requireActivity() instanceof ContextActivity) {
if (requireActivity() instanceof ContextActivity) { //Redraw decorations
int i = 0; statusAdapter.notifyItemRangeChanged(0, statuses.size());
for (Status status : statuses) { }
if (status.id.equals(statusPosted.in_reply_to_id)) { break;
statuses.add((i + 1), statusPosted);
statusAdapter.notifyItemInserted((i + 1));
if (requireActivity() instanceof ContextActivity) {
//Redraw decorations
statusAdapter.notifyItemRangeChanged(0, statuses.size());
} }
break; i++;
} }
i++;
} }
} }
} });
} }
} }
}; };

View file

@ -112,17 +112,19 @@ public class FragmentMastodonDirectMessage extends Fragment {
private final BroadcastReceiver broadcast_data = new BroadcastReceiver() { private final BroadcastReceiver broadcast_data = new BroadcastReceiver() {
@Override @Override
public void onReceive(android.content.Context context, Intent intent) { public void onReceive(android.content.Context context, Intent intent) {
Bundle b = intent.getExtras(); Bundle args = intent.getExtras();
if (b != null) { if (args != null) {
long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1);
if (b.getBoolean(Helper.RECEIVE_NEW_MESSAGE, false)) { new CachedBundle(requireActivity()).getBundle(bundleId, currentAccount, bundle -> {
Status statusReceived = (Status) b.getSerializable(Helper.RECEIVE_STATUS_ACTION); if (bundle.getBoolean(Helper.RECEIVE_NEW_MESSAGE, false)) {
if (statusReceived != null) { Status statusReceived = (Status) bundle.getSerializable(Helper.RECEIVE_STATUS_ACTION);
statuses.add(statusReceived); if (statusReceived != null) {
statusDirectMessageAdapter.notifyItemInserted(statuses.size() - 1); statuses.add(statusReceived);
initiliazeStatus(); statusDirectMessageAdapter.notifyItemInserted(statuses.size() - 1);
initiliazeStatus();
}
} }
} });
} }
} }
}; };

View file

@ -14,6 +14,8 @@ package app.fedilab.android.mastodon.ui.fragment.timeline;
* You should have received a copy of the GNU General Public License along with Fedilab; if not, * You should have received a copy of the GNU General Public License along with Fedilab; if not,
* see <http://www.gnu.org/licenses>. */ * see <http://www.gnu.org/licenses>. */
import static app.fedilab.android.BaseMainActivity.currentAccount;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@ -47,6 +49,7 @@ import app.fedilab.android.databinding.FragmentPaginationBinding;
import app.fedilab.android.mastodon.client.entities.api.Notification; import app.fedilab.android.mastodon.client.entities.api.Notification;
import app.fedilab.android.mastodon.client.entities.api.Notifications; import app.fedilab.android.mastodon.client.entities.api.Notifications;
import app.fedilab.android.mastodon.client.entities.api.Status; import app.fedilab.android.mastodon.client.entities.api.Status;
import app.fedilab.android.mastodon.client.entities.app.CachedBundle;
import app.fedilab.android.mastodon.client.entities.app.StatusCache; import app.fedilab.android.mastodon.client.entities.app.StatusCache;
import app.fedilab.android.mastodon.client.entities.app.Timeline; import app.fedilab.android.mastodon.client.entities.app.Timeline;
import app.fedilab.android.mastodon.exception.DBException; import app.fedilab.android.mastodon.exception.DBException;
@ -71,43 +74,46 @@ public class FragmentMastodonNotification extends Fragment implements Notificati
private final BroadcastReceiver receive_action = new BroadcastReceiver() { private final BroadcastReceiver receive_action = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
Bundle b = intent.getExtras(); Bundle args = intent.getExtras();
if (b != null) { if (args != null) {
Status receivedStatus = (Status) b.getSerializable(Helper.ARG_STATUS_ACTION); long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1);
String delete_all_for_account_id = b.getString(Helper.ARG_DELETE_ALL_FOR_ACCOUNT_ID); new CachedBundle(requireActivity()).getBundle(bundleId, currentAccount, bundle -> {
boolean refreshNotifications = b.getBoolean(Helper.ARG_REFRESH_NOTFICATION, false); Status receivedStatus = (Status) bundle.getSerializable(Helper.ARG_STATUS_ACTION);
if (refreshNotifications) { String delete_all_for_account_id = bundle.getString(Helper.ARG_DELETE_ALL_FOR_ACCOUNT_ID);
scrollToTop(); boolean refreshNotifications = bundle.getBoolean(Helper.ARG_REFRESH_NOTFICATION, false);
} else if (receivedStatus != null && notificationAdapter != null) { if (refreshNotifications) {
int position = getPosition(receivedStatus); scrollToTop();
if (position >= 0) { } else if (receivedStatus != null && notificationAdapter != null) {
if (notificationList.get(position).status != null) { int position = getPosition(receivedStatus);
notificationList.get(position).status.reblog = receivedStatus.reblog; if (position >= 0) {
notificationList.get(position).status.reblogged = receivedStatus.reblogged; if (notificationList.get(position).status != null) {
notificationList.get(position).status.favourited = receivedStatus.favourited; notificationList.get(position).status.reblog = receivedStatus.reblog;
notificationList.get(position).status.bookmarked = receivedStatus.bookmarked; notificationList.get(position).status.reblogged = receivedStatus.reblogged;
notificationList.get(position).status.favourites_count = receivedStatus.favourites_count; notificationList.get(position).status.favourited = receivedStatus.favourited;
notificationList.get(position).status.reblogs_count = receivedStatus.reblogs_count; notificationList.get(position).status.bookmarked = receivedStatus.bookmarked;
notificationAdapter.notifyItemChanged(position); notificationList.get(position).status.favourites_count = receivedStatus.favourites_count;
notificationList.get(position).status.reblogs_count = receivedStatus.reblogs_count;
notificationAdapter.notifyItemChanged(position);
}
} }
} } else if (delete_all_for_account_id != null) {
} else if (delete_all_for_account_id != null) { List<Notification> toRemove = new ArrayList<>();
List<Notification> toRemove = new ArrayList<>(); if (notificationList != null) {
if (notificationList != null) { for (int position = 0; position < notificationList.size(); position++) {
for (int position = 0; position < notificationList.size(); position++) { if (notificationList.get(position).account.id.equals(delete_all_for_account_id)) {
if (notificationList.get(position).account.id.equals(delete_all_for_account_id)) { toRemove.add(notificationList.get(position));
toRemove.add(notificationList.get(position)); }
}
}
if (toRemove.size() > 0) {
for (int i = 0; i < toRemove.size(); i++) {
int position = getPosition(toRemove.get(i));
notificationList.remove(position);
notificationAdapter.notifyItemRemoved(position);
} }
} }
} }
if (toRemove.size() > 0) { });
for (int i = 0; i < toRemove.size(); i++) {
int position = getPosition(toRemove.get(i));
notificationList.remove(position);
notificationAdapter.notifyItemRemoved(position);
}
}
}
} }
} }
}; };

View file

@ -94,88 +94,91 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
private final BroadcastReceiver receive_action = new BroadcastReceiver() { private final BroadcastReceiver receive_action = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
Bundle b = intent.getExtras(); Bundle args = intent.getExtras();
if (b != null) { if (args != null) {
Status receivedStatus = (Status) b.getSerializable(Helper.ARG_STATUS_ACTION); long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1);
String delete_statuses_for_user = b.getString(Helper.ARG_STATUS_ACCOUNT_ID_DELETED); new CachedBundle(requireActivity()).getBundle(bundleId, currentAccount, bundle -> {
String delete_all_for_account_id = b.getString(Helper.ARG_DELETE_ALL_FOR_ACCOUNT_ID); Status receivedStatus = (Status) bundle.getSerializable(Helper.ARG_STATUS_ACTION);
Status status_to_delete = (Status) b.getSerializable(Helper.ARG_STATUS_DELETED); String delete_statuses_for_user = bundle.getString(Helper.ARG_STATUS_ACCOUNT_ID_DELETED);
Status status_to_update = (Status) b.getSerializable(Helper.ARG_STATUS_UPDATED); String delete_all_for_account_id = bundle.getString(Helper.ARG_DELETE_ALL_FOR_ACCOUNT_ID);
Status statusPosted = (Status) b.getSerializable(Helper.ARG_STATUS_DELETED); Status status_to_delete = (Status) bundle.getSerializable(Helper.ARG_STATUS_DELETED);
boolean refreshAll = b.getBoolean(Helper.ARG_TIMELINE_REFRESH_ALL, false); Status status_to_update = (Status) bundle.getSerializable(Helper.ARG_STATUS_UPDATED);
if (receivedStatus != null && statusAdapter != null) { Status statusPosted = (Status) bundle.getSerializable(Helper.ARG_STATUS_DELETED);
int position = getPosition(receivedStatus); boolean refreshAll = bundle.getBoolean(Helper.ARG_TIMELINE_REFRESH_ALL, false);
if (position >= 0) { if (receivedStatus != null && statusAdapter != null) {
if (receivedStatus.reblog != null) { int position = getPosition(receivedStatus);
timelineStatuses.get(position).reblog = receivedStatus.reblog;
}
if (timelineStatuses.get(position).reblog != null) {
timelineStatuses.get(position).reblog.reblogged = receivedStatus.reblogged;
timelineStatuses.get(position).reblog.favourited = receivedStatus.favourited;
timelineStatuses.get(position).reblog.bookmarked = receivedStatus.bookmarked;
timelineStatuses.get(position).reblog.reblogs_count = receivedStatus.reblogs_count;
timelineStatuses.get(position).reblog.favourites_count = receivedStatus.favourites_count;
} else {
timelineStatuses.get(position).reblogged = receivedStatus.reblogged;
timelineStatuses.get(position).favourited = receivedStatus.favourited;
timelineStatuses.get(position).bookmarked = receivedStatus.bookmarked;
timelineStatuses.get(position).reblogs_count = receivedStatus.reblogs_count;
timelineStatuses.get(position).favourites_count = receivedStatus.favourites_count;
}
statusAdapter.notifyItemChanged(position);
}
} else if (delete_statuses_for_user != null && statusAdapter != null) {
List<Status> statusesToRemove = new ArrayList<>();
for (Status status : timelineStatuses) {
if (status != null && status.account != null && status.account.id != null && status.account.id.equals(delete_statuses_for_user)) {
statusesToRemove.add(status);
}
}
for (Status statusToRemove : statusesToRemove) {
int position = getPosition(statusToRemove);
if (position >= 0) { if (position >= 0) {
timelineStatuses.remove(position); if (receivedStatus.reblog != null) {
statusAdapter.notifyItemRemoved(position); timelineStatuses.get(position).reblog = receivedStatus.reblog;
}
if (timelineStatuses.get(position).reblog != null) {
timelineStatuses.get(position).reblog.reblogged = receivedStatus.reblogged;
timelineStatuses.get(position).reblog.favourited = receivedStatus.favourited;
timelineStatuses.get(position).reblog.bookmarked = receivedStatus.bookmarked;
timelineStatuses.get(position).reblog.reblogs_count = receivedStatus.reblogs_count;
timelineStatuses.get(position).reblog.favourites_count = receivedStatus.favourites_count;
} else {
timelineStatuses.get(position).reblogged = receivedStatus.reblogged;
timelineStatuses.get(position).favourited = receivedStatus.favourited;
timelineStatuses.get(position).bookmarked = receivedStatus.bookmarked;
timelineStatuses.get(position).reblogs_count = receivedStatus.reblogs_count;
timelineStatuses.get(position).favourites_count = receivedStatus.favourites_count;
}
statusAdapter.notifyItemChanged(position);
} }
} } else if (delete_statuses_for_user != null && statusAdapter != null) {
} else if (status_to_delete != null && statusAdapter != null) { List<Status> statusesToRemove = new ArrayList<>();
int position = getPosition(status_to_delete); for (Status status : timelineStatuses) {
if (position >= 0) { if (status != null && status.account != null && status.account.id != null && status.account.id.equals(delete_statuses_for_user)) {
timelineStatuses.remove(position); statusesToRemove.add(status);
statusAdapter.notifyItemRemoved(position);
}
} else if (status_to_update != null && statusAdapter != null) {
int position = getPosition(status_to_update);
if (position >= 0) {
timelineStatuses.set(position, status_to_update);
statusAdapter.notifyItemChanged(position);
}
} else if (statusPosted != null && statusAdapter != null && timelineType == Timeline.TimeLineEnum.HOME) {
timelineStatuses.add(0, statusPosted);
statusAdapter.notifyItemInserted(0);
} else if (delete_all_for_account_id != null) {
List<Status> toRemove = new ArrayList<>();
if (timelineStatuses != null) {
for (int position = 0; position < timelineStatuses.size(); position++) {
if (timelineStatuses.get(position).account.id.equals(delete_all_for_account_id)) {
toRemove.add(timelineStatuses.get(position));
} }
} }
} for (Status statusToRemove : statusesToRemove) {
if (toRemove.size() > 0) { int position = getPosition(statusToRemove);
for (int i = 0; i < toRemove.size(); i++) {
int position = getPosition(toRemove.get(i));
if (position >= 0) { if (position >= 0) {
timelineStatuses.remove(position); timelineStatuses.remove(position);
statusAdapter.notifyItemRemoved(position); statusAdapter.notifyItemRemoved(position);
} }
} }
} else if (status_to_delete != null && statusAdapter != null) {
int position = getPosition(status_to_delete);
if (position >= 0) {
timelineStatuses.remove(position);
statusAdapter.notifyItemRemoved(position);
}
} else if (status_to_update != null && statusAdapter != null) {
int position = getPosition(status_to_update);
if (position >= 0) {
timelineStatuses.set(position, status_to_update);
statusAdapter.notifyItemChanged(position);
}
} else if (statusPosted != null && statusAdapter != null && timelineType == Timeline.TimeLineEnum.HOME) {
timelineStatuses.add(0, statusPosted);
statusAdapter.notifyItemInserted(0);
} else if (delete_all_for_account_id != null) {
List<Status> toRemove = new ArrayList<>();
if (timelineStatuses != null) {
for (int position = 0; position < timelineStatuses.size(); position++) {
if (timelineStatuses.get(position).account.id.equals(delete_all_for_account_id)) {
toRemove.add(timelineStatuses.get(position));
}
}
}
if (toRemove.size() > 0) {
for (int i = 0; i < toRemove.size(); i++) {
int position = getPosition(toRemove.get(i));
if (position >= 0) {
timelineStatuses.remove(position);
statusAdapter.notifyItemRemoved(position);
}
}
}
} else if (refreshAll) {
refreshAllAdapters();
} }
} else if (refreshAll) { });
refreshAllAdapters();
}
} }
} }
}; };