Commit 85e462e2 authored by Thomas's avatar Thomas
Browse files

Apply for status

parent 1ff15b0f
Loading
Loading
Loading
Loading
+27 −9
Original line number Diff line number Diff line
@@ -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)
                            .setAction(getString(R.string.display), view -> {
                                Intent intentContext = new Intent(BaseMainActivity.this, ContextActivity.class);
                                intentContext.putExtra(Helper.ARG_STATUS, statusSent);
                                Bundle args = new Bundle();
                                args.putSerializable(Helper.ARG_STATUS, statusSent);
                                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();
                    //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) {
                        if (status != null) {
                            Intent intent = new Intent(activity, ContextActivity.class);
                            intent.putExtra(Helper.ARG_STATUS, status);
                            Bundle args = new Bundle();
                            args.putSerializable(Helper.ARG_STATUS, status);
                            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) {
                                if (status != null) {
                                    Intent intent = new Intent(activity, ContextActivity.class);
                                    intent.putExtra(Helper.ARG_STATUS, status);
                                    Bundle args = new Bundle();
                                    args.putSerializable(Helper.ARG_STATUS, status);
                                    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 {
                                    Toasty.error(activity, activity.getString(R.string.toast_error), Toasty.LENGTH_SHORT).show();
                                }
+75 −49
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ import app.fedilab.android.R;
import app.fedilab.android.activities.MainActivity;
import app.fedilab.android.databinding.ActivityConversationBinding;
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.exception.DBException;
import app.fedilab.android.mastodon.helper.Helper;
@@ -86,14 +87,24 @@ public class ContextActivity extends BaseActivity implements FragmentMastodonCon
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            getSupportActionBar().setDisplayShowHomeEnabled(true);
        }
        Bundle b = getIntent().getExtras();
        displayCW = sharedpreferences.getBoolean(getString(R.string.SET_EXPAND_CW), false);
        focusedStatus = null; // or other values
        if (b != null) {
            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);
        MastodonHelper.loadPPMastodon(binding.profilePicture, currentAccount.mastodon_account);

        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) {
            finish();
@@ -102,7 +113,7 @@ public class ContextActivity extends BaseActivity implements FragmentMastodonCon
        if (focusedStatusURI == null && remote_instance == null) {
            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);
        if (!checkRemotely) {
@@ -113,6 +124,7 @@ public class ContextActivity extends BaseActivity implements FragmentMastodonCon
        }
    }


    @Override
    protected void onSaveInstanceState(@NonNull Bundle outState) {
        super.onSaveInstanceState(outState);
@@ -120,9 +132,12 @@ public class ContextActivity extends BaseActivity implements FragmentMastodonCon
    }

    private void loadLocalConversation() {
        Bundle args = new Bundle();
        args.putSerializable(Helper.ARG_STATUS, focusedStatus);
        args.putString(Helper.ARG_REMOTE_INSTANCE, remote_instance);
        new CachedBundle(ContextActivity.this).insertBundle(args, currentAccount, bundleId -> {
            Bundle bundle = new Bundle();
        bundle.putSerializable(Helper.ARG_STATUS, focusedStatus);
        bundle.putString(Helper.ARG_REMOTE_INSTANCE, remote_instance);
            bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
            FragmentMastodonContext fragmentMastodonContext = new FragmentMastodonContext();
            fragmentMastodonContext.firstMessage = this;
            currentFragment = Helper.addFragment(getSupportFragmentManager(), R.id.nav_host_fragment_content_main, fragmentMastodonContext, bundle, null, null);
@@ -151,6 +166,7 @@ public class ContextActivity extends BaseActivity implements FragmentMastodonCon
                    }
                });
            }
        });
    }

    @Override
@@ -245,13 +261,17 @@ public class ContextActivity extends BaseActivity implements FragmentMastodonCon
                            String finalInstance = instance;
                            statusesVM.getStatus(instance, null, remoteId).observe(ContextActivity.this, status -> {
                                if (status != null) {
                                    Bundle args = new Bundle();
                                    args.putSerializable(Helper.ARG_STATUS, status);
                                    args.putString(Helper.ARG_REMOTE_INSTANCE, finalInstance);
                                    args.putString(Helper.ARG_FOCUSED_STATUS_URI, focusedStatusURI);
                                    new CachedBundle(ContextActivity.this).insertBundle(args, currentAccount, bundleId -> {
                                        Bundle bundle = new Bundle();
                                    bundle.putSerializable(Helper.ARG_STATUS, status);
                                    bundle.putString(Helper.ARG_REMOTE_INSTANCE, finalInstance);
                                    bundle.putString(Helper.ARG_FOCUSED_STATUS_URI, focusedStatusURI);
                                        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 {
                                    loadLocalConversation();
                                }
@@ -293,11 +313,17 @@ public class ContextActivity extends BaseActivity implements FragmentMastodonCon
                    statusesVM.getStatus(instance, null, remoteId).observe(ContextActivity.this, status -> {
                        if (status != null) {
                            Intent intentContext = new Intent(ContextActivity.this, ContextActivity.class);
                            intentContext.putExtra(Helper.ARG_STATUS, status);
                            intentContext.putExtra(Helper.ARG_FOCUSED_STATUS_URI, focusedStatusURI);
                            intentContext.putExtra(Helper.ARG_REMOTE_INSTANCE, finalInstance);
                            Bundle args = new Bundle();
                            args.putSerializable(Helper.ARG_STATUS, status);
                            args.putString(Helper.ARG_FOCUSED_STATUS_URI, focusedStatusURI);
                            args.putString(Helper.ARG_REMOTE_INSTANCE, finalInstance);
                            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 {
                            Toasty.warning(ContextActivity.this, getString(R.string.toast_error_fetch_message), Toasty.LENGTH_SHORT).show();
                        }
+17 −5
Original line number Diff line number Diff line
@@ -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.Status;
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.customsharing.CustomSharingAsyncTask;
import app.fedilab.android.mastodon.helper.customsharing.CustomSharingResponse;
@@ -65,23 +66,34 @@ public class CustomSharingActivity extends BaseBarActivity implements OnCustomSh
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(CustomSharingActivity.this);

        binding = ActivityCustomSharingBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        if (getSupportActionBar() != null) {
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            getSupportActionBar().setDisplayShowHomeEnabled(true);
        }
        Bundle b = getIntent().getExtras();
        Bundle args = getIntent().getExtras();
        status = null;
        if (b != null) {
            status = (Status) b.getSerializable(Helper.ARG_STATUS);
        if (args != null) {
            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) {
            finish();
            return;
        }

        SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(CustomSharingActivity.this);
        bundle_creator = status.account.acct;
        bundle_url = status.url;
        bundle_id = status.uri;
+53 −34
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import app.fedilab.android.BaseMainActivity;
import app.fedilab.android.R;
import app.fedilab.android.databinding.ActivityDirectMessageBinding;
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.exception.DBException;
import app.fedilab.android.mastodon.helper.Helper;
@@ -71,31 +72,48 @@ public class DirectMessageActivity extends BaseActivity implements FragmentMasto
        SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(this);
        float scale = sharedpreferences.getFloat(getString(R.string.SET_FONT_SCALE), 1.1f);
        binding.title.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18 * 1.1f / scale);

        MastodonHelper.loadPPMastodon(binding.profilePicture, currentAccount.mastodon_account);
        if (getSupportActionBar() != null) {
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            getSupportActionBar().setDisplayShowHomeEnabled(true);
        }
        Bundle b = getIntent().getExtras();
        Bundle args = getIntent().getExtras();
        displayCW = sharedpreferences.getBoolean(getString(R.string.SET_EXPAND_CW), false);

        if (args != null) {
            long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1);
            new CachedBundle(DirectMessageActivity.this).getBundle(bundleId, currentAccount, this::initializeAfterBundle);
        } else {
            initializeAfterBundle(null);
        }


    }

    private void initializeAfterBundle(Bundle bundle) {
        Status focusedStatus = null; // or other values
        if (b != null) {
            focusedStatus = (Status) b.getSerializable(Helper.ARG_STATUS);
            remote_instance = b.getString(Helper.ARG_REMOTE_INSTANCE, null);
        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) {
            finish();
            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);

        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, bundle, null, null);
            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, focusedStatus.id).observe(DirectMessageActivity.this, status -> {
            timelinesVM.getStatus(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, finalFocusedStatus.id).observe(DirectMessageActivity.this, status -> {
                if (status != null) {
                    StatusCache statusCache = new StatusCache();
                    statusCache.instance = BaseMainActivity.currentInstance;
@@ -116,8 +134,9 @@ public class DirectMessageActivity extends BaseActivity implements FragmentMasto
                    }).start();
                }
            });
    }
        });

    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
+22 −7
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ package app.fedilab.android.mastodon.activities;
 * see <http://www.gnu.org/licenses>. */

import static android.util.Patterns.WEB_URL;
import static app.fedilab.android.BaseMainActivity.currentAccount;

import android.Manifest;
import android.app.DownloadManager;
@@ -63,6 +64,7 @@ import app.fedilab.android.R;
import app.fedilab.android.databinding.ActivityMediaPagerBinding;
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.app.CachedBundle;
import app.fedilab.android.mastodon.helper.Helper;
import app.fedilab.android.mastodon.helper.MediaHelper;
import app.fedilab.android.mastodon.helper.TranslateHelper;
@@ -124,13 +126,26 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload

        fullscreen = false;
        flags = getWindow().getDecorView().getSystemUiVisibility();
        Bundle b = getIntent().getExtras();
        if (b != null) {
            mediaPosition = b.getInt(Helper.ARG_MEDIA_POSITION, 1);
            attachments = (ArrayList<Attachment>) b.getSerializable(Helper.ARG_MEDIA_ARRAY);
            mediaFromProfile = b.getBoolean(Helper.ARG_MEDIA_ARRAY_PROFILE, false);
            status = (Status) b.getSerializable(Helper.ARG_STATUS);
        Bundle args = getIntent().getExtras();
        if (args != null) {
            long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1);
            new CachedBundle(MediaActivity.this).getBundle(bundleId, currentAccount, this::initializeAfterBundle);
        } else {
            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) {
            attachments = new ArrayList<>();
            attachments.addAll(FragmentMediaProfile.mediaAttachmentProfile);
@@ -146,7 +161,6 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload
        }

        setTitle("");

        ScreenSlidePagerAdapter mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
        binding.mediaViewpager.setAdapter(mPagerAdapter);
        binding.mediaViewpager.setSaveEnabled(false);
@@ -239,6 +253,7 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload
        setFullscreen(true);
    }


    private Spannable linkify(Context context, String content) {
        if (content == null) {
            return new SpannableString("");
Loading