Apply for status

This commit is contained in:
Thomas 2024-01-10 15:58:27 +01:00
parent 1ff15b0f93
commit 85e462e276
14 changed files with 422 additions and 181 deletions

View file

@ -304,9 +304,15 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
Snackbar.make(binding.displaySnackBar, getString(R.string.message_has_been_sent), Snackbar.LENGTH_LONG) Snackbar.make(binding.displaySnackBar, getString(R.string.message_has_been_sent), Snackbar.LENGTH_LONG)
.setAction(getString(R.string.display), view -> { .setAction(getString(R.string.display), view -> {
Intent intentContext = new Intent(BaseMainActivity.this, ContextActivity.class); Intent intentContext = new Intent(BaseMainActivity.this, ContextActivity.class);
intentContext.putExtra(Helper.ARG_STATUS, statusSent); Bundle args = new Bundle();
intentContext.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); args.putSerializable(Helper.ARG_STATUS, statusSent);
startActivity(intentContext); new CachedBundle(BaseMainActivity.this).insertBundle(args, currentAccount, bundleId -> {
Bundle bundle = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
intentContext.putExtras(bundle);
intentContext.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intentContext);
});
}) })
.show(); .show();
//The message was edited, we need to update the timeline //The message was edited, we need to update the timeline
@ -782,9 +788,15 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
public void federatedStatus(Status status) { public void federatedStatus(Status status) {
if (status != null) { if (status != null) {
Intent intent = new Intent(activity, ContextActivity.class); Intent intent = new Intent(activity, ContextActivity.class);
intent.putExtra(Helper.ARG_STATUS, status); Bundle args = new Bundle();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); args.putSerializable(Helper.ARG_STATUS, status);
activity.startActivity(intent); new CachedBundle(activity).insertBundle(args, currentAccount, bundleId -> {
Bundle bundle = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
activity.startActivity(intent);
});
} }
} }
@ -1021,9 +1033,15 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
public void federatedStatus(Status status) { public void federatedStatus(Status status) {
if (status != null) { if (status != null) {
Intent intent = new Intent(activity, ContextActivity.class); Intent intent = new Intent(activity, ContextActivity.class);
intent.putExtra(Helper.ARG_STATUS, status); Bundle args = new Bundle();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); args.putSerializable(Helper.ARG_STATUS, status);
activity.startActivity(intent); new CachedBundle(activity).insertBundle(args, currentAccount, bundleId -> {
Bundle bundle = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
activity.startActivity(intent);
});
} else { } else {
Toasty.error(activity, activity.getString(R.string.toast_error), Toasty.LENGTH_SHORT).show(); Toasty.error(activity, activity.getString(R.string.toast_error), Toasty.LENGTH_SHORT).show();
} }

View file

@ -44,6 +44,7 @@ import app.fedilab.android.R;
import app.fedilab.android.activities.MainActivity; import app.fedilab.android.activities.MainActivity;
import app.fedilab.android.databinding.ActivityConversationBinding; import app.fedilab.android.databinding.ActivityConversationBinding;
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.exception.DBException; import app.fedilab.android.mastodon.exception.DBException;
import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.helper.Helper;
@ -86,14 +87,24 @@ public class ContextActivity extends BaseActivity implements FragmentMastodonCon
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true);
} }
Bundle b = getIntent().getExtras();
displayCW = sharedpreferences.getBoolean(getString(R.string.SET_EXPAND_CW), false); displayCW = sharedpreferences.getBoolean(getString(R.string.SET_EXPAND_CW), false);
focusedStatus = null; // or other values focusedStatus = null; // or other values
if (b != null) { MastodonHelper.loadPPMastodon(binding.profilePicture, currentAccount.mastodon_account);
focusedStatus = (Status) b.getSerializable(Helper.ARG_STATUS);
remote_instance = b.getString(Helper.ARG_REMOTE_INSTANCE, null);
focusedStatusURI = b.getString(Helper.ARG_FOCUSED_STATUS_URI, null);
Bundle args = getIntent().getExtras();
if (args != null) {
long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1);
new CachedBundle(ContextActivity.this).getBundle(bundleId, currentAccount, this::initializeAfterBundle);
} else {
initializeAfterBundle(null);
}
}
private void initializeAfterBundle(Bundle bundle) {
if (bundle != null) {
focusedStatus = (Status) bundle.getSerializable(Helper.ARG_STATUS);
remote_instance = bundle.getString(Helper.ARG_REMOTE_INSTANCE, null);
focusedStatusURI = bundle.getString(Helper.ARG_FOCUSED_STATUS_URI, null);
} }
if (focusedStatus == null || currentAccount == null || currentAccount.mastodon_account == null) { if (focusedStatus == null || currentAccount == null || currentAccount.mastodon_account == null) {
finish(); finish();
@ -102,7 +113,7 @@ public class ContextActivity extends BaseActivity implements FragmentMastodonCon
if (focusedStatusURI == null && remote_instance == null) { if (focusedStatusURI == null && remote_instance == null) {
focusedStatusURI = focusedStatus.uri; focusedStatusURI = focusedStatus.uri;
} }
MastodonHelper.loadPPMastodon(binding.profilePicture, currentAccount.mastodon_account); SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(this);
checkRemotely = sharedpreferences.getBoolean(getString(R.string.SET_CONVERSATION_REMOTELY), false); checkRemotely = sharedpreferences.getBoolean(getString(R.string.SET_CONVERSATION_REMOTELY), false);
if (!checkRemotely) { if (!checkRemotely) {
@ -113,6 +124,7 @@ public class ContextActivity extends BaseActivity implements FragmentMastodonCon
} }
} }
@Override @Override
protected void onSaveInstanceState(@NonNull Bundle outState) { protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
@ -120,37 +132,41 @@ public class ContextActivity extends BaseActivity implements FragmentMastodonCon
} }
private void loadLocalConversation() { private void loadLocalConversation() {
Bundle bundle = new Bundle(); Bundle args = new Bundle();
bundle.putSerializable(Helper.ARG_STATUS, focusedStatus); args.putSerializable(Helper.ARG_STATUS, focusedStatus);
bundle.putString(Helper.ARG_REMOTE_INSTANCE, remote_instance); args.putString(Helper.ARG_REMOTE_INSTANCE, remote_instance);
FragmentMastodonContext fragmentMastodonContext = new FragmentMastodonContext(); new CachedBundle(ContextActivity.this).insertBundle(args, currentAccount, bundleId -> {
fragmentMastodonContext.firstMessage = this; Bundle bundle = new Bundle();
currentFragment = Helper.addFragment(getSupportFragmentManager(), R.id.nav_host_fragment_content_main, fragmentMastodonContext, bundle, null, null); bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
//Update the status FragmentMastodonContext fragmentMastodonContext = new FragmentMastodonContext();
if (remote_instance == null) { fragmentMastodonContext.firstMessage = this;
StatusesVM timelinesVM = new ViewModelProvider(ContextActivity.this).get(StatusesVM.class); currentFragment = Helper.addFragment(getSupportFragmentManager(), R.id.nav_host_fragment_content_main, fragmentMastodonContext, bundle, null, null);
timelinesVM.getStatus(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, focusedStatus.id).observe(ContextActivity.this, status -> { //Update the status
if (status != null) { if (remote_instance == null) {
StatusCache statusCache = new StatusCache(); StatusesVM timelinesVM = new ViewModelProvider(ContextActivity.this).get(StatusesVM.class);
statusCache.instance = BaseMainActivity.currentInstance; timelinesVM.getStatus(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, focusedStatus.id).observe(ContextActivity.this, status -> {
statusCache.user_id = BaseMainActivity.currentUserID; if (status != null) {
statusCache.status = status; StatusCache statusCache = new StatusCache();
statusCache.status_id = status.id; statusCache.instance = BaseMainActivity.currentInstance;
//Update cache statusCache.user_id = BaseMainActivity.currentUserID;
new Thread(() -> { statusCache.status = status;
try { statusCache.status_id = status.id;
new StatusCache(getApplication()).updateIfExists(statusCache); //Update cache
Handler mainHandler = new Handler(Looper.getMainLooper()); new Thread(() -> {
//Update UI try {
Runnable myRunnable = () -> StatusAdapter.sendAction(ContextActivity.this, Helper.ARG_STATUS_ACTION, status, null); new StatusCache(getApplication()).updateIfExists(statusCache);
mainHandler.post(myRunnable); Handler mainHandler = new Handler(Looper.getMainLooper());
} catch (DBException e) { //Update UI
e.printStackTrace(); Runnable myRunnable = () -> StatusAdapter.sendAction(ContextActivity.this, Helper.ARG_STATUS_ACTION, status, null);
} mainHandler.post(myRunnable);
}).start(); } catch (DBException e) {
} e.printStackTrace();
}); }
} }).start();
}
});
}
});
} }
@Override @Override
@ -245,13 +261,17 @@ public class ContextActivity extends BaseActivity implements FragmentMastodonCon
String finalInstance = instance; String finalInstance = instance;
statusesVM.getStatus(instance, null, remoteId).observe(ContextActivity.this, status -> { statusesVM.getStatus(instance, null, remoteId).observe(ContextActivity.this, status -> {
if (status != null) { if (status != null) {
Bundle bundle = new Bundle(); Bundle args = new Bundle();
bundle.putSerializable(Helper.ARG_STATUS, status); args.putSerializable(Helper.ARG_STATUS, status);
bundle.putString(Helper.ARG_REMOTE_INSTANCE, finalInstance); args.putString(Helper.ARG_REMOTE_INSTANCE, finalInstance);
bundle.putString(Helper.ARG_FOCUSED_STATUS_URI, focusedStatusURI); args.putString(Helper.ARG_FOCUSED_STATUS_URI, focusedStatusURI);
FragmentMastodonContext fragmentMastodonContext = new FragmentMastodonContext(); new CachedBundle(ContextActivity.this).insertBundle(args, currentAccount, bundleId -> {
fragmentMastodonContext.firstMessage = ContextActivity.this; Bundle bundle = new Bundle();
currentFragment = Helper.addFragment(getSupportFragmentManager(), R.id.nav_host_fragment_content_main, fragmentMastodonContext, bundle, null, null); bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
FragmentMastodonContext fragmentMastodonContext = new FragmentMastodonContext();
fragmentMastodonContext.firstMessage = ContextActivity.this;
currentFragment = Helper.addFragment(getSupportFragmentManager(), R.id.nav_host_fragment_content_main, fragmentMastodonContext, bundle, null, null);
});
} else { } else {
loadLocalConversation(); loadLocalConversation();
} }
@ -293,11 +313,17 @@ public class ContextActivity extends BaseActivity implements FragmentMastodonCon
statusesVM.getStatus(instance, null, remoteId).observe(ContextActivity.this, status -> { statusesVM.getStatus(instance, null, remoteId).observe(ContextActivity.this, status -> {
if (status != null) { if (status != null) {
Intent intentContext = new Intent(ContextActivity.this, ContextActivity.class); Intent intentContext = new Intent(ContextActivity.this, ContextActivity.class);
intentContext.putExtra(Helper.ARG_STATUS, status); Bundle args = new Bundle();
intentContext.putExtra(Helper.ARG_FOCUSED_STATUS_URI, focusedStatusURI); args.putSerializable(Helper.ARG_STATUS, status);
intentContext.putExtra(Helper.ARG_REMOTE_INSTANCE, finalInstance); args.putString(Helper.ARG_FOCUSED_STATUS_URI, focusedStatusURI);
intentContext.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); args.putString(Helper.ARG_REMOTE_INSTANCE, finalInstance);
startActivity(intentContext); new CachedBundle(ContextActivity.this).insertBundle(args, currentAccount, bundleId -> {
Bundle bundle = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
intentContext.putExtras(bundle);
intentContext.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intentContext);
});
} else { } else {
Toasty.warning(ContextActivity.this, getString(R.string.toast_error_fetch_message), Toasty.LENGTH_SHORT).show(); Toasty.warning(ContextActivity.this, getString(R.string.toast_error_fetch_message), Toasty.LENGTH_SHORT).show();
} }

View file

@ -37,6 +37,7 @@ import app.fedilab.android.mastodon.client.entities.api.Attachment;
import app.fedilab.android.mastodon.client.entities.api.Emoji; import app.fedilab.android.mastodon.client.entities.api.Emoji;
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.api.Tag; import app.fedilab.android.mastodon.client.entities.api.Tag;
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.customsharing.CustomSharingAsyncTask; import app.fedilab.android.mastodon.helper.customsharing.CustomSharingAsyncTask;
import app.fedilab.android.mastodon.helper.customsharing.CustomSharingResponse; import app.fedilab.android.mastodon.helper.customsharing.CustomSharingResponse;
@ -65,23 +66,34 @@ public class CustomSharingActivity extends BaseBarActivity implements OnCustomSh
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(CustomSharingActivity.this);
binding = ActivityCustomSharingBinding.inflate(getLayoutInflater()); binding = ActivityCustomSharingBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot()); setContentView(binding.getRoot());
if (getSupportActionBar() != null) { if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true);
} }
Bundle b = getIntent().getExtras(); Bundle args = getIntent().getExtras();
status = null; status = null;
if (b != null) { if (args != null) {
status = (Status) b.getSerializable(Helper.ARG_STATUS); long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1);
new CachedBundle(CustomSharingActivity.this).getBundle(bundleId, currentAccount, this::initializeAfterBundle);
} else {
initializeAfterBundle(null);
}
}
private void initializeAfterBundle(Bundle bundle) {
if (bundle != null) {
status = (Status) bundle.getSerializable(Helper.ARG_STATUS);
} }
if (status == null) { if (status == null) {
finish(); finish();
return; return;
} }
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(CustomSharingActivity.this);
bundle_creator = status.account.acct; bundle_creator = status.account.acct;
bundle_url = status.url; bundle_url = status.url;
bundle_id = status.uri; bundle_id = status.uri;

View file

@ -39,6 +39,7 @@ import app.fedilab.android.BaseMainActivity;
import app.fedilab.android.R; import app.fedilab.android.R;
import app.fedilab.android.databinding.ActivityDirectMessageBinding; import app.fedilab.android.databinding.ActivityDirectMessageBinding;
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.exception.DBException; import app.fedilab.android.mastodon.exception.DBException;
import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.helper.Helper;
@ -71,53 +72,71 @@ public class DirectMessageActivity extends BaseActivity implements FragmentMasto
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(this);
float scale = sharedpreferences.getFloat(getString(R.string.SET_FONT_SCALE), 1.1f); float scale = sharedpreferences.getFloat(getString(R.string.SET_FONT_SCALE), 1.1f);
binding.title.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18 * 1.1f / scale); binding.title.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18 * 1.1f / scale);
MastodonHelper.loadPPMastodon(binding.profilePicture, currentAccount.mastodon_account);
if (getSupportActionBar() != null) { if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true);
} }
Bundle b = getIntent().getExtras(); Bundle args = getIntent().getExtras();
displayCW = sharedpreferences.getBoolean(getString(R.string.SET_EXPAND_CW), false); displayCW = sharedpreferences.getBoolean(getString(R.string.SET_EXPAND_CW), false);
Status focusedStatus = null; // or other values
if (b != null) { if (args != null) {
focusedStatus = (Status) b.getSerializable(Helper.ARG_STATUS); long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1);
remote_instance = b.getString(Helper.ARG_REMOTE_INSTANCE, null); new CachedBundle(DirectMessageActivity.this).getBundle(bundleId, currentAccount, this::initializeAfterBundle);
} else {
initializeAfterBundle(null);
} }
}
private void initializeAfterBundle(Bundle bundle) {
Status focusedStatus = null; // or other values
if (bundle != null) {
focusedStatus = (Status) bundle.getSerializable(Helper.ARG_STATUS);
remote_instance = bundle.getString(Helper.ARG_REMOTE_INSTANCE, null);
}
if (focusedStatus == null || currentAccount == null || currentAccount.mastodon_account == null) { if (focusedStatus == null || currentAccount == null || currentAccount.mastodon_account == null) {
finish(); finish();
return; return;
} }
MastodonHelper.loadPPMastodon(binding.profilePicture, currentAccount.mastodon_account);
Bundle bundle = new Bundle();
bundle.putSerializable(Helper.ARG_STATUS, focusedStatus);
bundle.putString(Helper.ARG_REMOTE_INSTANCE, remote_instance);
FragmentMastodonDirectMessage FragmentMastodonDirectMessage = new FragmentMastodonDirectMessage();
FragmentMastodonDirectMessage.firstMessage = this;
currentFragment = (FragmentMastodonDirectMessage) Helper.addFragment(getSupportFragmentManager(), R.id.nav_host_fragment_content_main, FragmentMastodonDirectMessage, bundle, null, null);
StatusesVM timelinesVM = new ViewModelProvider(DirectMessageActivity.this).get(StatusesVM.class);
timelinesVM.getStatus(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, focusedStatus.id).observe(DirectMessageActivity.this, status -> {
if (status != null) {
StatusCache statusCache = new StatusCache();
statusCache.instance = BaseMainActivity.currentInstance;
statusCache.user_id = BaseMainActivity.currentUserID;
statusCache.status = status;
statusCache.status_id = status.id;
//Update cache
new Thread(() -> {
try {
new StatusCache(getApplication()).updateIfExists(statusCache);
Handler mainHandler = new Handler(Looper.getMainLooper());
//Update UI
Runnable myRunnable = () -> StatusAdapter.sendAction(DirectMessageActivity.this, Helper.ARG_STATUS_ACTION, status, null);
mainHandler.post(myRunnable);
} catch (DBException e) {
e.printStackTrace();
}
}).start();
}
});
}
Bundle args = new Bundle();
args.putSerializable(Helper.ARG_STATUS, focusedStatus);
args.putString(Helper.ARG_REMOTE_INSTANCE, remote_instance);
Status finalFocusedStatus = focusedStatus;
new CachedBundle(DirectMessageActivity.this).insertBundle(args, currentAccount, bundleId -> {
Bundle args2 = new Bundle();
args2.putLong(Helper.ARG_INTENT_ID, bundleId);
FragmentMastodonDirectMessage FragmentMastodonDirectMessage = new FragmentMastodonDirectMessage();
FragmentMastodonDirectMessage.firstMessage = this;
currentFragment = (FragmentMastodonDirectMessage) Helper.addFragment(getSupportFragmentManager(), R.id.nav_host_fragment_content_main, FragmentMastodonDirectMessage, args2, null, null);
StatusesVM timelinesVM = new ViewModelProvider(DirectMessageActivity.this).get(StatusesVM.class);
timelinesVM.getStatus(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, finalFocusedStatus.id).observe(DirectMessageActivity.this, status -> {
if (status != null) {
StatusCache statusCache = new StatusCache();
statusCache.instance = BaseMainActivity.currentInstance;
statusCache.user_id = BaseMainActivity.currentUserID;
statusCache.status = status;
statusCache.status_id = status.id;
//Update cache
new Thread(() -> {
try {
new StatusCache(getApplication()).updateIfExists(statusCache);
Handler mainHandler = new Handler(Looper.getMainLooper());
//Update UI
Runnable myRunnable = () -> StatusAdapter.sendAction(DirectMessageActivity.this, Helper.ARG_STATUS_ACTION, status, null);
mainHandler.post(myRunnable);
} catch (DBException e) {
e.printStackTrace();
}
}).start();
}
});
});
}
@Override @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) { public void onActivityResult(int requestCode, int resultCode, Intent data) {

View file

@ -15,6 +15,7 @@ package app.fedilab.android.mastodon.activities;
* see <http://www.gnu.org/licenses>. */ * see <http://www.gnu.org/licenses>. */
import static android.util.Patterns.WEB_URL; import static android.util.Patterns.WEB_URL;
import static app.fedilab.android.BaseMainActivity.currentAccount;
import android.Manifest; import android.Manifest;
import android.app.DownloadManager; import android.app.DownloadManager;
@ -63,6 +64,7 @@ import app.fedilab.android.R;
import app.fedilab.android.databinding.ActivityMediaPagerBinding; import app.fedilab.android.databinding.ActivityMediaPagerBinding;
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.helper.Helper; import app.fedilab.android.mastodon.helper.Helper;
import app.fedilab.android.mastodon.helper.MediaHelper; import app.fedilab.android.mastodon.helper.MediaHelper;
import app.fedilab.android.mastodon.helper.TranslateHelper; import app.fedilab.android.mastodon.helper.TranslateHelper;
@ -124,13 +126,26 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload
fullscreen = false; fullscreen = false;
flags = getWindow().getDecorView().getSystemUiVisibility(); flags = getWindow().getDecorView().getSystemUiVisibility();
Bundle b = getIntent().getExtras(); Bundle args = getIntent().getExtras();
if (b != null) { if (args != null) {
mediaPosition = b.getInt(Helper.ARG_MEDIA_POSITION, 1); long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1);
attachments = (ArrayList<Attachment>) b.getSerializable(Helper.ARG_MEDIA_ARRAY); new CachedBundle(MediaActivity.this).getBundle(bundleId, currentAccount, this::initializeAfterBundle);
mediaFromProfile = b.getBoolean(Helper.ARG_MEDIA_ARRAY_PROFILE, false); } else {
status = (Status) b.getSerializable(Helper.ARG_STATUS); initializeAfterBundle(null);
} }
}
private void initializeAfterBundle(Bundle bundle) {
if (bundle != null) {
mediaPosition = bundle.getInt(Helper.ARG_MEDIA_POSITION, 1);
attachments = (ArrayList<Attachment>) bundle.getSerializable(Helper.ARG_MEDIA_ARRAY);
mediaFromProfile = bundle.getBoolean(Helper.ARG_MEDIA_ARRAY_PROFILE, false);
status = (Status) bundle.getSerializable(Helper.ARG_STATUS);
}
if (mediaFromProfile && FragmentMediaProfile.mediaAttachmentProfile != null) { if (mediaFromProfile && FragmentMediaProfile.mediaAttachmentProfile != null) {
attachments = new ArrayList<>(); attachments = new ArrayList<>();
attachments.addAll(FragmentMediaProfile.mediaAttachmentProfile); attachments.addAll(FragmentMediaProfile.mediaAttachmentProfile);
@ -146,7 +161,6 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload
} }
setTitle(""); setTitle("");
ScreenSlidePagerAdapter mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager()); ScreenSlidePagerAdapter mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
binding.mediaViewpager.setAdapter(mPagerAdapter); binding.mediaViewpager.setAdapter(mPagerAdapter);
binding.mediaViewpager.setSaveEnabled(false); binding.mediaViewpager.setSaveEnabled(false);
@ -239,6 +253,7 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload
setFullscreen(true); setFullscreen(true);
} }
private Spannable linkify(Context context, String content) { private Spannable linkify(Context context, String content) {
if (content == null) { if (content == null) {
return new SpannableString(""); return new SpannableString("");

View file

@ -15,6 +15,7 @@ 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 static app.fedilab.android.BaseMainActivity.currentInstance; import static app.fedilab.android.BaseMainActivity.currentInstance;
import static app.fedilab.android.BaseMainActivity.currentToken; import static app.fedilab.android.BaseMainActivity.currentToken;
@ -38,6 +39,7 @@ import app.fedilab.android.mastodon.client.entities.api.Account;
import app.fedilab.android.mastodon.client.entities.api.Accounts; import app.fedilab.android.mastodon.client.entities.api.Accounts;
import app.fedilab.android.mastodon.client.entities.api.RelationShip; import app.fedilab.android.mastodon.client.entities.api.RelationShip;
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.helper.Helper; import app.fedilab.android.mastodon.helper.Helper;
import app.fedilab.android.mastodon.ui.drawer.AccountAdapter; import app.fedilab.android.mastodon.ui.drawer.AccountAdapter;
import app.fedilab.android.mastodon.viewmodel.mastodon.AccountsVM; import app.fedilab.android.mastodon.viewmodel.mastodon.AccountsVM;
@ -70,12 +72,23 @@ public class StatusInfoActivity extends BaseActivity {
} }
accountList = new ArrayList<>(); accountList = new ArrayList<>();
checkRemotely = false; checkRemotely = false;
Bundle b = getIntent().getExtras(); Bundle args = getIntent().getExtras();
if (b != null) { if (args != null) {
type = (typeOfInfo) b.getSerializable(Helper.ARG_TYPE_OF_INFO); long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1);
status = (Status) b.getSerializable(Helper.ARG_STATUS); new CachedBundle(StatusInfoActivity.this).getBundle(bundleId, currentAccount, this::initializeAfterBundle);
checkRemotely = b.getBoolean(Helper.ARG_CHECK_REMOTELY, false); } else {
initializeAfterBundle(null);
} }
}
private void initializeAfterBundle(Bundle bundle) {
if (bundle != null) {
type = (typeOfInfo) bundle.getSerializable(Helper.ARG_TYPE_OF_INFO);
status = (Status) bundle.getSerializable(Helper.ARG_STATUS);
checkRemotely = bundle.getBoolean(Helper.ARG_CHECK_REMOTELY, false);
}
if (type == null || status == null) { if (type == null || status == null) {
finish(); finish();
return; return;
@ -138,6 +151,7 @@ public class StatusInfoActivity extends BaseActivity {
} }
} }
private void manageView(Accounts accounts) { private void manageView(Accounts accounts) {
binding.loadingNextAccounts.setVisibility(View.GONE); binding.loadingNextAccounts.setVisibility(View.GONE);
if (accountList != null && accounts != null && accounts.accounts != null) { if (accountList != null && accounts != null && accounts.accounts != null) {

View file

@ -45,16 +45,25 @@ public class TimelineActivity extends BaseBarActivity {
if (getSupportActionBar() != null) { if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
} }
Bundle b = getIntent().getExtras(); Bundle args = getIntent().getExtras();
if (args != null) {
long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1);
new CachedBundle(TimelineActivity.this).getBundle(bundleId, currentAccount, this::initializeAfterBundle);
} else {
initializeAfterBundle(null);
}
}
private void initializeAfterBundle(Bundle bundle) {
Timeline.TimeLineEnum timelineType = null; Timeline.TimeLineEnum timelineType = null;
String lemmy_post_id = null; String lemmy_post_id = null;
PinnedTimeline pinnedTimeline = null; PinnedTimeline pinnedTimeline = null;
Status status = null; Status status = null;
if (b != null) { if (bundle != null) {
timelineType = (Timeline.TimeLineEnum) b.get(Helper.ARG_TIMELINE_TYPE); timelineType = (Timeline.TimeLineEnum) bundle.get(Helper.ARG_TIMELINE_TYPE);
lemmy_post_id = b.getString(Helper.ARG_LEMMY_POST_ID, null); lemmy_post_id = bundle.getString(Helper.ARG_LEMMY_POST_ID, null);
pinnedTimeline = (PinnedTimeline) b.getSerializable(Helper.ARG_REMOTE_INSTANCE); pinnedTimeline = (PinnedTimeline) bundle.getSerializable(Helper.ARG_REMOTE_INSTANCE);
status = (Status) b.getSerializable(Helper.ARG_STATUS); status = (Status) bundle.getSerializable(Helper.ARG_STATUS);
} }
if (pinnedTimeline != null && pinnedTimeline.remoteInstance != null) { if (pinnedTimeline != null && pinnedTimeline.remoteInstance != null) {
setTitle(pinnedTimeline.remoteInstance.host); setTitle(pinnedTimeline.remoteInstance.host);
@ -68,13 +77,12 @@ public class TimelineActivity extends BaseBarActivity {
args.putSerializable(Helper.ARG_STATUS, status); args.putSerializable(Helper.ARG_STATUS, status);
} }
new CachedBundle(TimelineActivity.this).insertBundle(args, currentAccount, bundleId -> { new CachedBundle(TimelineActivity.this).insertBundle(args, currentAccount, bundleId -> {
Bundle bundle = new Bundle(); Bundle bundle1 = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId); bundle1.putLong(Helper.ARG_INTENT_ID, bundleId);
fragmentMastodonTimeline.setArguments(bundle); fragmentMastodonTimeline.setArguments(bundle1);
getSupportFragmentManager().beginTransaction() getSupportFragmentManager().beginTransaction()
.add(R.id.fragment_container_view, fragmentMastodonTimeline).commit(); .add(R.id.fragment_container_view, fragmentMastodonTimeline).commit();
}); });
} }

View file

@ -627,9 +627,15 @@ public class SpannableHelper {
@Override @Override
public void federatedStatus(Status status) { public void federatedStatus(Status status) {
Intent intent = new Intent(context, ContextActivity.class); Intent intent = new Intent(context, ContextActivity.class);
intent.putExtra(Helper.ARG_STATUS, status); Bundle args = new Bundle();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); args.putSerializable(Helper.ARG_STATUS, status);
context.startActivity(intent); new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> {
Bundle bundle = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
});
} }
@Override @Override
@ -663,9 +669,15 @@ public class SpannableHelper {
@Override @Override
public void federatedStatus(Status status) { public void federatedStatus(Status status) {
Intent intent = new Intent(context, ContextActivity.class); Intent intent = new Intent(context, ContextActivity.class);
intent.putExtra(Helper.ARG_STATUS, status); Bundle args = new Bundle();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); args.putSerializable(Helper.ARG_STATUS, status);
context.startActivity(intent); new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> {
Bundle bundle = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
});
} }
@Override @Override
@ -699,9 +711,15 @@ public class SpannableHelper {
@Override @Override
public void federatedStatus(Status status) { public void federatedStatus(Status status) {
Intent intent = new Intent(context, ContextActivity.class); Intent intent = new Intent(context, ContextActivity.class);
intent.putExtra(Helper.ARG_STATUS, status); Bundle args = new Bundle();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); args.putSerializable(Helper.ARG_STATUS, status);
context.startActivity(intent); new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> {
Bundle bundle = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
});
} }
@Override @Override

View file

@ -15,6 +15,7 @@ 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 static app.fedilab.android.BaseMainActivity.currentNightMode; import static app.fedilab.android.BaseMainActivity.currentNightMode;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
@ -22,6 +23,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -49,13 +51,14 @@ import app.fedilab.android.R;
import app.fedilab.android.databinding.DrawerConversationBinding; import app.fedilab.android.databinding.DrawerConversationBinding;
import app.fedilab.android.databinding.ThumbnailBinding; import app.fedilab.android.databinding.ThumbnailBinding;
import app.fedilab.android.mastodon.activities.ContextActivity; import app.fedilab.android.mastodon.activities.ContextActivity;
import app.fedilab.android.mastodon.activities.DirectMessageActivity;
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.Attachment; import app.fedilab.android.mastodon.client.entities.api.Attachment;
import app.fedilab.android.mastodon.client.entities.api.Conversation; import app.fedilab.android.mastodon.client.entities.api.Conversation;
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.helper.Helper; import app.fedilab.android.mastodon.helper.Helper;
import app.fedilab.android.mastodon.helper.MastodonHelper; import app.fedilab.android.mastodon.helper.MastodonHelper;
import app.fedilab.android.mastodon.activities.DirectMessageActivity;
public class ConversationAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { public class ConversationAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
@ -220,8 +223,14 @@ public class ConversationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
} else { } else {
intent = new Intent(context, ContextActivity.class); intent = new Intent(context, ContextActivity.class);
} }
intent.putExtra(Helper.ARG_STATUS, conversation.last_status); Bundle args = new Bundle();
context.startActivity(intent); args.putSerializable(Helper.ARG_STATUS, conversation.last_status);
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.attachmentsListContainer.setOnTouchListener((v, event) -> { holder.binding.attachmentsListContainer.setOnTouchListener((v, event) -> {
@ -232,8 +241,14 @@ public class ConversationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
} else { } else {
intent = new Intent(context, ContextActivity.class); intent = new Intent(context, ContextActivity.class);
} }
intent.putExtra(Helper.ARG_STATUS, conversation.last_status); Bundle args = new Bundle();
context.startActivity(intent); args.putSerializable(Helper.ARG_STATUS, conversation.last_status);
new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> {
Bundle bundle = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
intent.putExtras(bundle);
context.startActivity(intent);
});
} }
return false; return false;
}); });

View file

@ -14,6 +14,8 @@ package app.fedilab.android.mastodon.ui.drawer;
* 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.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@ -31,6 +33,7 @@ import app.fedilab.android.databinding.DrawerMediaBinding;
import app.fedilab.android.mastodon.activities.ContextActivity; import app.fedilab.android.mastodon.activities.ContextActivity;
import app.fedilab.android.mastodon.activities.MediaActivity; import app.fedilab.android.mastodon.activities.MediaActivity;
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.app.CachedBundle;
import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.helper.Helper;
import app.fedilab.android.mastodon.ui.fragment.media.FragmentMediaProfile; import app.fedilab.android.mastodon.ui.fragment.media.FragmentMediaProfile;
@ -89,13 +92,19 @@ public class ImageAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
holder.binding.media.setOnLongClickListener(v -> { holder.binding.media.setOnLongClickListener(v -> {
Intent intentContext = new Intent(context, ContextActivity.class); Intent intentContext = new Intent(context, ContextActivity.class);
Bundle args = new Bundle();
if (attachment != null) { if (attachment != null) {
intentContext.putExtra(Helper.ARG_STATUS, attachment.status); args.putSerializable(Helper.ARG_STATUS, attachment.status);
} else { } else {
return false; return false;
} }
intentContext.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> {
context.startActivity(intentContext); Bundle bundle = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
intentContext.putExtras(bundle);
intentContext.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intentContext);
});
return false; return false;
}); });
} }

View file

@ -503,8 +503,14 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
return; return;
} }
Intent intent = new Intent(context, ContextActivity.class); Intent intent = new Intent(context, ContextActivity.class);
intent.putExtra(Helper.ARG_STATUS, statusToDeal.quote); Bundle args = new Bundle();
context.startActivity(intent); args.putSerializable(Helper.ARG_STATUS, statusToDeal.quote);
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.quotedMessage.cardviewContainer.setStrokeColor(ThemeHelper.getAttColor(context, R.attr.colorPrimary)); holder.binding.quotedMessage.cardviewContainer.setStrokeColor(ThemeHelper.getAttColor(context, R.attr.colorPrimary));
holder.binding.quotedMessage.statusContent.setText( holder.binding.quotedMessage.statusContent.setText(
@ -1773,20 +1779,32 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
holder.binding.reblogInfo.setOnClickListener(v -> { holder.binding.reblogInfo.setOnClickListener(v -> {
if (statusToDeal.reblogs_count > 0) { if (statusToDeal.reblogs_count > 0) {
Intent intent = new Intent(context, StatusInfoActivity.class); Intent intent = new Intent(context, StatusInfoActivity.class);
intent.putExtra(Helper.ARG_TYPE_OF_INFO, StatusInfoActivity.typeOfInfo.BOOSTED_BY); Bundle args = new Bundle();
intent.putExtra(Helper.ARG_STATUS, statusToDeal); args.putSerializable(Helper.ARG_STATUS, statusToDeal);
intent.putExtra(Helper.ARG_CHECK_REMOTELY, remote); args.putSerializable(Helper.ARG_TYPE_OF_INFO, StatusInfoActivity.typeOfInfo.BOOSTED_BY);
context.startActivity(intent); args.putBoolean(Helper.ARG_CHECK_REMOTELY, remote);
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.favouriteInfo.setOnClickListener(v -> { holder.binding.favouriteInfo.setOnClickListener(v -> {
if (statusToDeal.favourites_count > 0) { if (statusToDeal.favourites_count > 0) {
Intent intent = new Intent(context, StatusInfoActivity.class); Intent intent = new Intent(context, StatusInfoActivity.class);
intent.putExtra(Helper.ARG_TYPE_OF_INFO, StatusInfoActivity.typeOfInfo.LIKED_BY); Bundle args = new Bundle();
intent.putExtra(Helper.ARG_STATUS, statusToDeal); args.putSerializable(Helper.ARG_STATUS, statusToDeal);
intent.putExtra(Helper.ARG_CHECK_REMOTELY, remote); args.putSerializable(Helper.ARG_TYPE_OF_INFO, StatusInfoActivity.typeOfInfo.LIKED_BY);
context.startActivity(intent); args.putBoolean(Helper.ARG_CHECK_REMOTELY, remote);
new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> {
Bundle bundle = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
intent.putExtras(bundle);
context.startActivity(intent);
});
} }
}); });
@ -2002,22 +2020,31 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
return; return;
} }
if (context instanceof ContextActivity && !remote) { if (context instanceof ContextActivity && !remote) {
Bundle bundle = new Bundle(); Bundle args = new Bundle();
bundle.putSerializable(Helper.ARG_STATUS, statusToDeal); args.putSerializable(Helper.ARG_STATUS, statusToDeal);
Fragment fragment = Helper.addFragment(((AppCompatActivity) context).getSupportFragmentManager(), R.id.nav_host_fragment_content_main, new FragmentMastodonContext(), bundle, null, FragmentMastodonContext.class.getName()); new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> {
((ContextActivity) context).setCurrentFragment((FragmentMastodonContext) fragment); Bundle bundle = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
Fragment fragment = Helper.addFragment(((AppCompatActivity) context).getSupportFragmentManager(), R.id.nav_host_fragment_content_main, new FragmentMastodonContext(), bundle, null, FragmentMastodonContext.class.getName());
((ContextActivity) context).setCurrentFragment((FragmentMastodonContext) fragment);
});
} else { } else {
if (remote) { if (remote) {
//Lemmy main post that should open Lemmy threads //Lemmy main post that should open Lemmy threads
if (adapter instanceof StatusAdapter && ((StatusAdapter) adapter).type == RemoteInstance.InstanceType.LEMMY && status.lemmy_post_id != null) { if (adapter instanceof StatusAdapter && ((StatusAdapter) adapter).type == RemoteInstance.InstanceType.LEMMY && status.lemmy_post_id != null) {
Bundle bundle = new Bundle(); Bundle args = new Bundle();
bundle.putSerializable(Helper.ARG_REMOTE_INSTANCE, ((StatusAdapter) adapter).pinnedTimeline); args.putSerializable(Helper.ARG_REMOTE_INSTANCE, ((StatusAdapter) adapter).pinnedTimeline);
bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.REMOTE); args.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.REMOTE);
bundle.putString(Helper.ARG_LEMMY_POST_ID, status.lemmy_post_id); args.putString(Helper.ARG_LEMMY_POST_ID, status.lemmy_post_id);
bundle.putSerializable(Helper.ARG_STATUS, status); args.putSerializable(Helper.ARG_STATUS, status);
Intent intent = new Intent(context, TimelineActivity.class); Intent intent = new Intent(context, TimelineActivity.class);
intent.putExtras(bundle); 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);
});
} //Classic other cases for remote instances that will search the remote context } //Classic other cases for remote instances that will search the remote context
else if (!(context instanceof ContextActivity)) { //We are not already checking a remote conversation else if (!(context instanceof ContextActivity)) { //We are not already checking a remote conversation
Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show(); Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show();
@ -2026,8 +2053,14 @@ 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, ContextActivity.class); Intent intent = new Intent(context, ContextActivity.class);
intent.putExtra(Helper.ARG_STATUS, fetchedStatus); Bundle args = new Bundle();
context.startActivity(intent); args.putSerializable(Helper.ARG_STATUS, 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();
} }
@ -2047,8 +2080,14 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
} }
} else { } else {
Intent intent = new Intent(context, ContextActivity.class); Intent intent = new Intent(context, ContextActivity.class);
intent.putExtra(Helper.ARG_STATUS, statusToDeal); Bundle args = new Bundle();
context.startActivity(intent); args.putSerializable(Helper.ARG_STATUS, statusToDeal);
new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> {
Bundle bundle = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
intent.putExtras(bundle);
context.startActivity(intent);
});
} }
} }
}); });
@ -2262,8 +2301,14 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
return true; return true;
} else if (itemId == R.id.action_report) { } else if (itemId == R.id.action_report) {
Intent intent = new Intent(context, ReportActivity.class); Intent intent = new Intent(context, ReportActivity.class);
intent.putExtra(Helper.ARG_STATUS, statusToDeal); Bundle args = new Bundle();
context.startActivity(intent); args.putSerializable(Helper.ARG_STATUS, statusToDeal);
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 if (itemId == R.id.action_copy) { } else if (itemId == R.id.action_copy) {
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
String content; String content;
@ -2317,8 +2362,14 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
context.startActivity(Intent.createChooser(sendIntent, context.getString(R.string.share_with))); context.startActivity(Intent.createChooser(sendIntent, context.getString(R.string.share_with)));
} else if (itemId == R.id.action_custom_sharing) { } else if (itemId == R.id.action_custom_sharing) {
Intent intent = new Intent(context, CustomSharingActivity.class); Intent intent = new Intent(context, CustomSharingActivity.class);
intent.putExtra(Helper.ARG_STATUS, statusToDeal); Bundle args = new Bundle();
context.startActivity(intent); args.putSerializable(Helper.ARG_STATUS, statusToDeal);
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 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 b = new Bundle();
@ -3183,8 +3234,14 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
}); });
holder.bindingArt.bottomBanner.setOnClickListener(v -> { holder.bindingArt.bottomBanner.setOnClickListener(v -> {
Intent intent = new Intent(context, ContextActivity.class); Intent intent = new Intent(context, ContextActivity.class);
intent.putExtra(Helper.ARG_STATUS, status); Bundle args = new Bundle();
context.startActivity(intent); args.putSerializable(Helper.ARG_STATUS, status);
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 if (viewHolder.getItemViewType() == STATUS_PIXELFED) { } else if (viewHolder.getItemViewType() == STATUS_PIXELFED) {
Status statusToDeal = status.reblog != null ? status.reblog : status; Status statusToDeal = status.reblog != null ? status.reblog : status;
@ -3223,8 +3280,14 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
}); });
holder.bindingPixelfed.bottomBanner.setOnClickListener(v -> { holder.bindingPixelfed.bottomBanner.setOnClickListener(v -> {
Intent intent = new Intent(context, ContextActivity.class); Intent intent = new Intent(context, ContextActivity.class);
intent.putExtra(Helper.ARG_STATUS, statusToDeal); Bundle args = new Bundle();
context.startActivity(intent); args.putSerializable(Helper.ARG_STATUS, statusToDeal);
new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> {
Bundle bundle = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
intent.putExtras(bundle);
context.startActivity(intent);
});
}); });
} }
} }

View file

@ -14,6 +14,7 @@ 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 static app.fedilab.android.mastodon.activities.ContextActivity.displayCW; import static app.fedilab.android.mastodon.activities.ContextActivity.displayCW;
import static app.fedilab.android.mastodon.activities.ContextActivity.expand; import static app.fedilab.android.mastodon.activities.ContextActivity.expand;
@ -42,6 +43,7 @@ import app.fedilab.android.databinding.FragmentPaginationBinding;
import app.fedilab.android.mastodon.activities.ContextActivity; import app.fedilab.android.mastodon.activities.ContextActivity;
import app.fedilab.android.mastodon.client.entities.api.Context; import app.fedilab.android.mastodon.client.entities.api.Context;
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.Timeline; import app.fedilab.android.mastodon.client.entities.app.Timeline;
import app.fedilab.android.mastodon.helper.DividerDecoration; import app.fedilab.android.mastodon.helper.DividerDecoration;
import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.helper.Helper;
@ -158,10 +160,21 @@ public class FragmentMastodonContext extends Fragment {
pullToRefresh = false; pullToRefresh = false;
focusedStatusURI = null; focusedStatusURI = null;
refresh = true; refresh = true;
binding = FragmentPaginationBinding.inflate(inflater, container, false);
if (getArguments() != null) { if (getArguments() != null) {
focusedStatus = (Status) getArguments().getSerializable(Helper.ARG_STATUS); long bundleId = getArguments().getLong(Helper.ARG_INTENT_ID, -1);
remote_instance = getArguments().getString(Helper.ARG_REMOTE_INSTANCE, null); new CachedBundle(requireActivity()).getBundle(bundleId, currentAccount, this::initializeAfterBundle);
focusedStatusURI = getArguments().getString(Helper.ARG_FOCUSED_STATUS_URI, null); } else {
initializeAfterBundle(null);
}
return binding.getRoot();
}
private void initializeAfterBundle(Bundle bundle) {
if (bundle != null) {
focusedStatus = (Status) bundle.getSerializable(Helper.ARG_STATUS);
remote_instance = bundle.getString(Helper.ARG_REMOTE_INSTANCE, null);
focusedStatusURI = bundle.getString(Helper.ARG_FOCUSED_STATUS_URI, null);
} }
if (remote_instance != null) { if (remote_instance != null) {
user_instance = remote_instance; user_instance = remote_instance;
@ -174,7 +187,7 @@ public class FragmentMastodonContext extends Fragment {
getChildFragmentManager().beginTransaction().remove(this).commit(); getChildFragmentManager().beginTransaction().remove(this).commit();
} }
binding = FragmentPaginationBinding.inflate(inflater, container, false);
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity()); SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity());
boolean displayScrollBar = sharedpreferences.getBoolean(getString(R.string.SET_TIMELINE_SCROLLBAR), false); boolean displayScrollBar = sharedpreferences.getBoolean(getString(R.string.SET_TIMELINE_SCROLLBAR), false);
binding.recyclerView.setVerticalScrollBarEnabled(displayScrollBar); binding.recyclerView.setVerticalScrollBarEnabled(displayScrollBar);
@ -202,9 +215,9 @@ public class FragmentMastodonContext extends Fragment {
} }
ContextCompat.registerReceiver(requireActivity(), receive_action, new IntentFilter(Helper.RECEIVE_STATUS_ACTION), ContextCompat.RECEIVER_NOT_EXPORTED); ContextCompat.registerReceiver(requireActivity(), receive_action, new IntentFilter(Helper.RECEIVE_STATUS_ACTION), ContextCompat.RECEIVER_NOT_EXPORTED);
return binding.getRoot();
} }
public void refresh() { public void refresh() {
if (statuses != null) { if (statuses != null) {
for (Status status : statuses) { for (Status status : statuses) {

View file

@ -82,6 +82,7 @@ import app.fedilab.android.mastodon.client.entities.api.Context;
import app.fedilab.android.mastodon.client.entities.api.Mention; import app.fedilab.android.mastodon.client.entities.api.Mention;
import app.fedilab.android.mastodon.client.entities.api.Poll; import app.fedilab.android.mastodon.client.entities.api.Poll;
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;
@ -131,8 +132,21 @@ public class FragmentMastodonDirectMessage extends Fragment {
focusedStatus = null; focusedStatus = null;
pullToRefresh = false; pullToRefresh = false;
binding = FragmentDirectMessageBinding.inflate(inflater, container, false);
if (getArguments() != null) { if (getArguments() != null) {
focusedStatus = (Status) getArguments().getSerializable(Helper.ARG_STATUS); long bundleId = getArguments().getLong(Helper.ARG_INTENT_ID, -1);
new CachedBundle(requireActivity()).getBundle(bundleId, currentAccount, this::initializeAfterBundle);
} else {
initializeAfterBundle(null);
}
return binding.getRoot();
}
private void initializeAfterBundle(Bundle bundle) {
if (bundle != null) {
focusedStatus = (Status) bundle.getSerializable(Helper.ARG_STATUS);
} }
user_instance = MainActivity.currentInstance; user_instance = MainActivity.currentInstance;
user_token = MainActivity.currentToken; user_token = MainActivity.currentToken;
@ -140,7 +154,7 @@ public class FragmentMastodonDirectMessage extends Fragment {
if (focusedStatus == null) { if (focusedStatus == null) {
getChildFragmentManager().beginTransaction().remove(this).commit(); getChildFragmentManager().beginTransaction().remove(this).commit();
} }
binding = FragmentDirectMessageBinding.inflate(inflater, container, false);
statusesVM = new ViewModelProvider(FragmentMastodonDirectMessage.this).get(StatusesVM.class); statusesVM = new ViewModelProvider(FragmentMastodonDirectMessage.this).get(StatusesVM.class);
binding.recyclerView.setNestedScrollingEnabled(true); binding.recyclerView.setNestedScrollingEnabled(true);
this.statuses = new ArrayList<>(); this.statuses = new ArrayList<>();
@ -216,10 +230,8 @@ public class FragmentMastodonDirectMessage extends Fragment {
} }
}); });
return binding.getRoot();
} }
private void onSubmit(StatusDraft statusDraft) { private void onSubmit(StatusDraft statusDraft) {
new Thread(() -> { new Thread(() -> {
if (statusDraft.instance == null) { if (statusDraft.instance == null) {

View file

@ -43,7 +43,6 @@ import org.json.JSONObject;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.IDN; import java.net.IDN;
import java.net.URL; import java.net.URL;
import java.net.URLDecoder; import java.net.URLDecoder;