mirror of
				https://codeberg.org/tom79/Fedilab.git
				synced 2025-10-20 11:20:16 +03:00 
			
		
		
		
	Check status
This commit is contained in:
		
							parent
							
								
									d45ac1b9f9
								
							
						
					
					
						commit
						7546d79533
					
				
					 6 changed files with 177 additions and 31 deletions
				
			
		| 
						 | 
					@ -18,11 +18,13 @@ package app.fedilab.android.activities;
 | 
				
			||||||
import static app.fedilab.android.BaseMainActivity.currentAccount;
 | 
					import static app.fedilab.android.BaseMainActivity.currentAccount;
 | 
				
			||||||
import static app.fedilab.android.ui.drawer.StatusAdapter.sendAction;
 | 
					import static app.fedilab.android.ui.drawer.StatusAdapter.sendAction;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import android.content.Intent;
 | 
				
			||||||
import android.content.SharedPreferences;
 | 
					import android.content.SharedPreferences;
 | 
				
			||||||
import android.content.res.Resources;
 | 
					import android.content.res.Resources;
 | 
				
			||||||
import android.os.Bundle;
 | 
					import android.os.Bundle;
 | 
				
			||||||
import android.os.Handler;
 | 
					import android.os.Handler;
 | 
				
			||||||
import android.os.Looper;
 | 
					import android.os.Looper;
 | 
				
			||||||
 | 
					import android.util.Log;
 | 
				
			||||||
import android.util.TypedValue;
 | 
					import android.util.TypedValue;
 | 
				
			||||||
import android.view.Menu;
 | 
					import android.view.Menu;
 | 
				
			||||||
import android.view.MenuItem;
 | 
					import android.view.MenuItem;
 | 
				
			||||||
| 
						 | 
					@ -35,27 +37,32 @@ import androidx.preference.PreferenceManager;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import app.fedilab.android.BaseMainActivity;
 | 
					import app.fedilab.android.BaseMainActivity;
 | 
				
			||||||
import app.fedilab.android.R;
 | 
					import app.fedilab.android.R;
 | 
				
			||||||
 | 
					import app.fedilab.android.client.entities.api.Account;
 | 
				
			||||||
import app.fedilab.android.client.entities.api.Status;
 | 
					import app.fedilab.android.client.entities.api.Status;
 | 
				
			||||||
import app.fedilab.android.client.entities.app.StatusCache;
 | 
					import app.fedilab.android.client.entities.app.StatusCache;
 | 
				
			||||||
import app.fedilab.android.databinding.ActivityConversationBinding;
 | 
					import app.fedilab.android.databinding.ActivityConversationBinding;
 | 
				
			||||||
import app.fedilab.android.exception.DBException;
 | 
					import app.fedilab.android.exception.DBException;
 | 
				
			||||||
 | 
					import app.fedilab.android.helper.CrossActionHelper;
 | 
				
			||||||
import app.fedilab.android.helper.Helper;
 | 
					import app.fedilab.android.helper.Helper;
 | 
				
			||||||
import app.fedilab.android.helper.MastodonHelper;
 | 
					import app.fedilab.android.helper.MastodonHelper;
 | 
				
			||||||
import app.fedilab.android.ui.fragment.timeline.FragmentMastodonContext;
 | 
					import app.fedilab.android.ui.fragment.timeline.FragmentMastodonContext;
 | 
				
			||||||
import app.fedilab.android.viewmodel.mastodon.StatusesVM;
 | 
					import app.fedilab.android.viewmodel.mastodon.StatusesVM;
 | 
				
			||||||
 | 
					import es.dmoral.toasty.Toasty;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class ContextActivity extends BaseActivity {
 | 
					public class ContextActivity extends BaseActivity implements FragmentMastodonContext.FirstMessage {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static boolean expand;
 | 
					    public static boolean expand;
 | 
				
			||||||
    public static boolean displayCW;
 | 
					    public static boolean displayCW;
 | 
				
			||||||
    public static Resources.Theme theme;
 | 
					    public static Resources.Theme theme;
 | 
				
			||||||
    Fragment currentFragment;
 | 
					    Fragment currentFragment;
 | 
				
			||||||
 | 
					    private Status firstMessage;
 | 
				
			||||||
 | 
					    private String remote_instance;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    protected void onCreate(Bundle savedInstanceState) {
 | 
					    protected void onCreate(Bundle savedInstanceState) {
 | 
				
			||||||
        super.onCreate(savedInstanceState);
 | 
					        super.onCreate(savedInstanceState);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        app.fedilab.android.databinding.ActivityConversationBinding binding = ActivityConversationBinding.inflate(getLayoutInflater());
 | 
					        ActivityConversationBinding binding = ActivityConversationBinding.inflate(getLayoutInflater());
 | 
				
			||||||
        setContentView(binding.getRoot());
 | 
					        setContentView(binding.getRoot());
 | 
				
			||||||
        setSupportActionBar(binding.toolbar);
 | 
					        setSupportActionBar(binding.toolbar);
 | 
				
			||||||
        ActionBar actionBar = getSupportActionBar();
 | 
					        ActionBar actionBar = getSupportActionBar();
 | 
				
			||||||
| 
						 | 
					@ -75,8 +82,10 @@ public class ContextActivity extends BaseActivity {
 | 
				
			||||||
        Bundle b = getIntent().getExtras();
 | 
					        Bundle b = 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
 | 
					        Status focusedStatus = null; // or other values
 | 
				
			||||||
        if (b != null)
 | 
					        if (b != null) {
 | 
				
			||||||
            focusedStatus = (Status) b.getSerializable(Helper.ARG_STATUS);
 | 
					            focusedStatus = (Status) b.getSerializable(Helper.ARG_STATUS);
 | 
				
			||||||
 | 
					            remote_instance = b.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;
 | 
				
			||||||
| 
						 | 
					@ -84,29 +93,34 @@ public class ContextActivity extends BaseActivity {
 | 
				
			||||||
        MastodonHelper.loadPPMastodon(binding.profilePicture, currentAccount.mastodon_account);
 | 
					        MastodonHelper.loadPPMastodon(binding.profilePicture, currentAccount.mastodon_account);
 | 
				
			||||||
        Bundle bundle = new Bundle();
 | 
					        Bundle bundle = new Bundle();
 | 
				
			||||||
        bundle.putSerializable(Helper.ARG_STATUS, focusedStatus);
 | 
					        bundle.putSerializable(Helper.ARG_STATUS, focusedStatus);
 | 
				
			||||||
        currentFragment = Helper.addFragment(getSupportFragmentManager(), R.id.nav_host_fragment_content_main, new FragmentMastodonContext(), bundle, null, null);
 | 
					        bundle.putString(Helper.ARG_REMOTE_INSTANCE, remote_instance);
 | 
				
			||||||
        StatusesVM timelinesVM = new ViewModelProvider(ContextActivity.this).get(StatusesVM.class);
 | 
					        FragmentMastodonContext fragmentMastodonContext = new FragmentMastodonContext();
 | 
				
			||||||
        timelinesVM.getStatus(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, focusedStatus.id).observe(ContextActivity.this, status -> {
 | 
					        fragmentMastodonContext.firstMessage = this;
 | 
				
			||||||
            if (status != null) {
 | 
					        currentFragment = Helper.addFragment(getSupportFragmentManager(), R.id.nav_host_fragment_content_main, fragmentMastodonContext, bundle, null, null);
 | 
				
			||||||
                StatusCache statusCache = new StatusCache();
 | 
					        if (remote_instance == null) {
 | 
				
			||||||
                statusCache.instance = BaseMainActivity.currentInstance;
 | 
					            StatusesVM timelinesVM = new ViewModelProvider(ContextActivity.this).get(StatusesVM.class);
 | 
				
			||||||
                statusCache.user_id = BaseMainActivity.currentUserID;
 | 
					            timelinesVM.getStatus(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, focusedStatus.id).observe(ContextActivity.this, status -> {
 | 
				
			||||||
                statusCache.status = status;
 | 
					                if (status != null) {
 | 
				
			||||||
                statusCache.status_id = status.id;
 | 
					                    StatusCache statusCache = new StatusCache();
 | 
				
			||||||
                //Update cache
 | 
					                    statusCache.instance = BaseMainActivity.currentInstance;
 | 
				
			||||||
                new Thread(() -> {
 | 
					                    statusCache.user_id = BaseMainActivity.currentUserID;
 | 
				
			||||||
                    try {
 | 
					                    statusCache.status = status;
 | 
				
			||||||
                        new StatusCache(getApplication()).updateIfExists(statusCache);
 | 
					                    statusCache.status_id = status.id;
 | 
				
			||||||
                        Handler mainHandler = new Handler(Looper.getMainLooper());
 | 
					                    //Update cache
 | 
				
			||||||
                        //Update UI
 | 
					                    new Thread(() -> {
 | 
				
			||||||
                        Runnable myRunnable = () -> sendAction(ContextActivity.this, Helper.ARG_STATUS_ACTION, status, null);
 | 
					                        try {
 | 
				
			||||||
                        mainHandler.post(myRunnable);
 | 
					                            new StatusCache(getApplication()).updateIfExists(statusCache);
 | 
				
			||||||
                    } catch (DBException e) {
 | 
					                            Handler mainHandler = new Handler(Looper.getMainLooper());
 | 
				
			||||||
                        e.printStackTrace();
 | 
					                            //Update UI
 | 
				
			||||||
                    }
 | 
					                            Runnable myRunnable = () -> sendAction(ContextActivity.this, Helper.ARG_STATUS_ACTION, status, null);
 | 
				
			||||||
                }).start();
 | 
					                            mainHandler.post(myRunnable);
 | 
				
			||||||
            }
 | 
					                        } catch (DBException e) {
 | 
				
			||||||
        });
 | 
					                            e.printStackTrace();
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					                    }).start();
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -126,6 +140,10 @@ public class ContextActivity extends BaseActivity {
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            itemDisplayCW.setIcon(R.drawable.ic_outline_remove_red_eye_24);
 | 
					            itemDisplayCW.setIcon(R.drawable.ic_outline_remove_red_eye_24);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        MenuItem action_remote = menu.findItem(R.id.action_remote);
 | 
				
			||||||
 | 
					        if (remote_instance != null) {
 | 
				
			||||||
 | 
					            action_remote.setVisible(false);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        return true;
 | 
					        return true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -151,8 +169,52 @@ public class ContextActivity extends BaseActivity {
 | 
				
			||||||
                ((FragmentMastodonContext) currentFragment).refresh();
 | 
					                ((FragmentMastodonContext) currentFragment).refresh();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            invalidateOptionsMenu();
 | 
					            invalidateOptionsMenu();
 | 
				
			||||||
 | 
					        } else if (item.getItemId() == R.id.action_remote) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (firstMessage == null) {
 | 
				
			||||||
 | 
					                Toasty.warning(ContextActivity.this, getString(R.string.toast_try_later), Toasty.LENGTH_SHORT).show();
 | 
				
			||||||
 | 
					                return true;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            if (firstMessage.account.acct != null) {
 | 
				
			||||||
 | 
					                String[] splitAcct = firstMessage.account.acct.split("@");
 | 
				
			||||||
 | 
					                String instance;
 | 
				
			||||||
 | 
					                if (splitAcct.length > 1) {
 | 
				
			||||||
 | 
					                    instance = splitAcct[1];
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    Toasty.info(ContextActivity.this, getString(R.string.toast_on_your_instance), Toasty.LENGTH_SHORT).show();
 | 
				
			||||||
 | 
					                    return true;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                Log.v(Helper.TAG, "firstMessage.uri: " + firstMessage.uri);
 | 
				
			||||||
 | 
					                Log.v(Helper.TAG, "instance: " + instance);
 | 
				
			||||||
 | 
					                CrossActionHelper.fetchStatusInRemoteInstance(ContextActivity.this, firstMessage.uri, instance, new CrossActionHelper.Callback() {
 | 
				
			||||||
 | 
					                    @Override
 | 
				
			||||||
 | 
					                    public void federatedStatus(Status status) {
 | 
				
			||||||
 | 
					                        Log.v(Helper.TAG, ">status: " + status);
 | 
				
			||||||
 | 
					                        if (status != null) {
 | 
				
			||||||
 | 
					                            Intent intentContext = new Intent(ContextActivity.this, ContextActivity.class);
 | 
				
			||||||
 | 
					                            intentContext.putExtra(Helper.ARG_STATUS, status);
 | 
				
			||||||
 | 
					                            intentContext.putExtra(Helper.ARG_REMOTE_INSTANCE, true);
 | 
				
			||||||
 | 
					                            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();
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    @Override
 | 
				
			||||||
 | 
					                    public void federatedAccount(Account account) {
 | 
				
			||||||
 | 
					                        Log.v(Helper.TAG, ">account: " + account);
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                });
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                Toasty.warning(ContextActivity.this, getString(R.string.toast_error_fetch_message), Toasty.LENGTH_SHORT).show();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return true;
 | 
					        return true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void get(Status status) {
 | 
				
			||||||
 | 
					        firstMessage = status;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -20,6 +20,7 @@ import android.content.SharedPreferences;
 | 
				
			||||||
import android.os.Bundle;
 | 
					import android.os.Bundle;
 | 
				
			||||||
import android.os.Handler;
 | 
					import android.os.Handler;
 | 
				
			||||||
import android.os.Looper;
 | 
					import android.os.Looper;
 | 
				
			||||||
 | 
					import android.util.Log;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import androidx.annotation.NonNull;
 | 
					import androidx.annotation.NonNull;
 | 
				
			||||||
import androidx.appcompat.app.AlertDialog;
 | 
					import androidx.appcompat.app.AlertDialog;
 | 
				
			||||||
| 
						 | 
					@ -439,6 +440,48 @@ public class CrossActionHelper {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Fetch and federate the remote status
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public static void fetchStatusInRemoteInstance(@NonNull Context context, String url, String instance, Callback callback) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        MastodonSearchService mastodonSearchService = init(context, instance);
 | 
				
			||||||
 | 
					        new Thread(() -> {
 | 
				
			||||||
 | 
					            Call<Results> resultsCall = mastodonSearchService.search(null, url, null, "statuses", null, null, null, null, null, null, null);
 | 
				
			||||||
 | 
					            Results results = null;
 | 
				
			||||||
 | 
					            Log.v(Helper.TAG, ">request: " + resultsCall.request());
 | 
				
			||||||
 | 
					            if (resultsCall != null) {
 | 
				
			||||||
 | 
					                try {
 | 
				
			||||||
 | 
					                    Response<Results> resultsResponse = resultsCall.execute();
 | 
				
			||||||
 | 
					                    if (resultsResponse.isSuccessful()) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        results = resultsResponse.body();
 | 
				
			||||||
 | 
					                        if (results != null) {
 | 
				
			||||||
 | 
					                            if (results.statuses == null) {
 | 
				
			||||||
 | 
					                                results.statuses = new ArrayList<>();
 | 
				
			||||||
 | 
					                            }
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					                    } else {
 | 
				
			||||||
 | 
					                        Log.v(Helper.TAG, ">err: " + resultsResponse.errorBody().string());
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                } catch (IOException e) {
 | 
				
			||||||
 | 
					                    e.printStackTrace();
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            Handler mainHandler = new Handler(Looper.getMainLooper());
 | 
				
			||||||
 | 
					            Results finalResults = results;
 | 
				
			||||||
 | 
					            Runnable myRunnable = () -> {
 | 
				
			||||||
 | 
					                Log.v(Helper.TAG, ">finalResults.statuses " + finalResults.statuses);
 | 
				
			||||||
 | 
					                if (finalResults != null && finalResults.statuses != null && finalResults.statuses.size() > 0) {
 | 
				
			||||||
 | 
					                    callback.federatedStatus(finalResults.statuses.get(0));
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            };
 | 
				
			||||||
 | 
					            mainHandler.post(myRunnable);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        }).start();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Fetch and federate the remote status
 | 
					     * Fetch and federate the remote status
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -34,9 +34,9 @@ import androidx.recyclerview.widget.LinearLayoutManager;
 | 
				
			||||||
import java.util.ArrayList;
 | 
					import java.util.ArrayList;
 | 
				
			||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import app.fedilab.android.BaseMainActivity;
 | 
					 | 
				
			||||||
import app.fedilab.android.R;
 | 
					import app.fedilab.android.R;
 | 
				
			||||||
import app.fedilab.android.activities.ContextActivity;
 | 
					import app.fedilab.android.activities.ContextActivity;
 | 
				
			||||||
 | 
					import app.fedilab.android.activities.MainActivity;
 | 
				
			||||||
import app.fedilab.android.client.entities.api.Context;
 | 
					import app.fedilab.android.client.entities.api.Context;
 | 
				
			||||||
import app.fedilab.android.client.entities.api.Status;
 | 
					import app.fedilab.android.client.entities.api.Status;
 | 
				
			||||||
import app.fedilab.android.client.entities.app.Timeline;
 | 
					import app.fedilab.android.client.entities.app.Timeline;
 | 
				
			||||||
| 
						 | 
					@ -54,6 +54,8 @@ public class FragmentMastodonContext extends Fragment {
 | 
				
			||||||
    private StatusesVM statusesVM;
 | 
					    private StatusesVM statusesVM;
 | 
				
			||||||
    private List<Status> statuses;
 | 
					    private List<Status> statuses;
 | 
				
			||||||
    private StatusAdapter statusAdapter;
 | 
					    private StatusAdapter statusAdapter;
 | 
				
			||||||
 | 
					    public FirstMessage firstMessage;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //Handle actions that can be done in other fragments
 | 
					    //Handle actions that can be done in other fragments
 | 
				
			||||||
    private final BroadcastReceiver receive_action = new BroadcastReceiver() {
 | 
					    private final BroadcastReceiver receive_action = new BroadcastReceiver() {
 | 
				
			||||||
        @Override
 | 
					        @Override
 | 
				
			||||||
| 
						 | 
					@ -116,8 +118,10 @@ public class FragmentMastodonContext extends Fragment {
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    private Status focusedStatus;
 | 
					    private Status focusedStatus;
 | 
				
			||||||
 | 
					    private String remote_instance;
 | 
				
			||||||
    private Status firstStatus;
 | 
					    private Status firstStatus;
 | 
				
			||||||
    private boolean pullToRefresh;
 | 
					    private boolean pullToRefresh;
 | 
				
			||||||
 | 
					    private String user_token, user_instance;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Return the position of the status in the ArrayList
 | 
					     * Return the position of the status in the ArrayList
 | 
				
			||||||
| 
						 | 
					@ -145,17 +149,26 @@ public class FragmentMastodonContext extends Fragment {
 | 
				
			||||||
        pullToRefresh = false;
 | 
					        pullToRefresh = false;
 | 
				
			||||||
        if (getArguments() != null) {
 | 
					        if (getArguments() != null) {
 | 
				
			||||||
            focusedStatus = (Status) getArguments().getSerializable(Helper.ARG_STATUS);
 | 
					            focusedStatus = (Status) getArguments().getSerializable(Helper.ARG_STATUS);
 | 
				
			||||||
 | 
					            remote_instance = getArguments().getString(Helper.ARG_REMOTE_INSTANCE, null);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (remote_instance != null) {
 | 
				
			||||||
 | 
					            user_instance = remote_instance;
 | 
				
			||||||
 | 
					            user_token = null;
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            user_instance = MainActivity.currentInstance;
 | 
				
			||||||
 | 
					            user_token = MainActivity.currentToken;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        if (focusedStatus == null) {
 | 
					        if (focusedStatus == null) {
 | 
				
			||||||
            getChildFragmentManager().beginTransaction().remove(this).commit();
 | 
					            getChildFragmentManager().beginTransaction().remove(this).commit();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        binding = FragmentPaginationBinding.inflate(inflater, container, false);
 | 
					        binding = FragmentPaginationBinding.inflate(inflater, container, false);
 | 
				
			||||||
        statusesVM = new ViewModelProvider(FragmentMastodonContext.this).get(StatusesVM.class);
 | 
					        statusesVM = new ViewModelProvider(FragmentMastodonContext.this).get(StatusesVM.class);
 | 
				
			||||||
        binding.recyclerView.setNestedScrollingEnabled(true);
 | 
					        binding.recyclerView.setNestedScrollingEnabled(true);
 | 
				
			||||||
        this.statuses = new ArrayList<>();
 | 
					        this.statuses = new ArrayList<>();
 | 
				
			||||||
        focusedStatus.isFocused = true;
 | 
					        focusedStatus.isFocused = true;
 | 
				
			||||||
        this.statuses.add(focusedStatus);
 | 
					        this.statuses.add(focusedStatus);
 | 
				
			||||||
        statusAdapter = new StatusAdapter(this.statuses, Timeline.TimeLineEnum.UNKNOWN, false, true, false);
 | 
					        statusAdapter = new StatusAdapter(this.statuses, Timeline.TimeLineEnum.UNKNOWN, false, true, remote_instance != null);
 | 
				
			||||||
        binding.swipeContainer.setRefreshing(false);
 | 
					        binding.swipeContainer.setRefreshing(false);
 | 
				
			||||||
        LinearLayoutManager mLayoutManager = new LinearLayoutManager(requireActivity());
 | 
					        LinearLayoutManager mLayoutManager = new LinearLayoutManager(requireActivity());
 | 
				
			||||||
        binding.recyclerView.setLayoutManager(mLayoutManager);
 | 
					        binding.recyclerView.setLayoutManager(mLayoutManager);
 | 
				
			||||||
| 
						 | 
					@ -164,12 +177,12 @@ public class FragmentMastodonContext extends Fragment {
 | 
				
			||||||
            if (this.statuses.size() > 0) {
 | 
					            if (this.statuses.size() > 0) {
 | 
				
			||||||
                binding.swipeContainer.setRefreshing(true);
 | 
					                binding.swipeContainer.setRefreshing(true);
 | 
				
			||||||
                pullToRefresh = true;
 | 
					                pullToRefresh = true;
 | 
				
			||||||
                statusesVM.getContext(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, focusedStatus.id)
 | 
					                statusesVM.getContext(user_instance, user_token, focusedStatus.id)
 | 
				
			||||||
                        .observe(getViewLifecycleOwner(), this::initializeContextView);
 | 
					                        .observe(getViewLifecycleOwner(), this::initializeContextView);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
        if (focusedStatus != null) {
 | 
					        if (focusedStatus != null) {
 | 
				
			||||||
            statusesVM.getContext(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, focusedStatus.id)
 | 
					            statusesVM.getContext(user_instance, user_token, focusedStatus.id)
 | 
				
			||||||
                    .observe(getViewLifecycleOwner(), this::initializeContextView);
 | 
					                    .observe(getViewLifecycleOwner(), this::initializeContextView);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        LocalBroadcastManager.getInstance(requireActivity()).registerReceiver(receive_action, new IntentFilter(Helper.RECEIVE_STATUS_ACTION));
 | 
					        LocalBroadcastManager.getInstance(requireActivity()).registerReceiver(receive_action, new IntentFilter(Helper.RECEIVE_STATUS_ACTION));
 | 
				
			||||||
| 
						 | 
					@ -196,7 +209,7 @@ public class FragmentMastodonContext extends Fragment {
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                id = focusedStatus.id;
 | 
					                id = focusedStatus.id;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            statusesVM.getContext(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, id)
 | 
					            statusesVM.getContext(user_instance, user_token, id)
 | 
				
			||||||
                    .observe(FragmentMastodonContext.this, this::initializeContextView);
 | 
					                    .observe(FragmentMastodonContext.this, this::initializeContextView);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -228,6 +241,10 @@ public class FragmentMastodonContext extends Fragment {
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            firstStatus = statuses.get(0);
 | 
					            firstStatus = statuses.get(0);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        if (firstMessage != null) {
 | 
				
			||||||
 | 
					            firstMessage.get(firstStatus);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        int statusPosition = context.ancestors.size();
 | 
					        int statusPosition = context.ancestors.size();
 | 
				
			||||||
        //Build the array of statuses
 | 
					        //Build the array of statuses
 | 
				
			||||||
        statuses.addAll(0, context.ancestors);
 | 
					        statuses.addAll(0, context.ancestors);
 | 
				
			||||||
| 
						 | 
					@ -250,4 +267,8 @@ public class FragmentMastodonContext extends Fragment {
 | 
				
			||||||
        super.onDestroyView();
 | 
					        super.onDestroyView();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public interface FirstMessage {
 | 
				
			||||||
 | 
					        void get(Status status);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,10 @@
 | 
				
			||||||
 | 
					<vector xmlns:android="http://schemas.android.com/apk/res/android"
 | 
				
			||||||
 | 
					    android:width="24dp"
 | 
				
			||||||
 | 
					    android:height="24dp"
 | 
				
			||||||
 | 
					    android:tint="?attr/colorControlNormal"
 | 
				
			||||||
 | 
					    android:viewportWidth="24"
 | 
				
			||||||
 | 
					    android:viewportHeight="24">
 | 
				
			||||||
 | 
					    <path
 | 
				
			||||||
 | 
					        android:fillColor="@android:color/white"
 | 
				
			||||||
 | 
					        android:pathData="M20.94,11c-0.46,-4.17 -3.77,-7.48 -7.94,-7.94V1h-2v2.06C6.83,3.52 3.52,6.83 3.06,11H1v2h2.06c0.46,4.17 3.77,7.48 7.94,7.94V23h2v-2.06c4.17,-0.46 7.48,-3.77 7.94,-7.94H23v-2h-2.06zM12,19c-3.87,0 -7,-3.13 -7,-7s3.13,-7 7,-7 7,3.13 7,7 -3.13,7 -7,7z" />
 | 
				
			||||||
 | 
					</vector>
 | 
				
			||||||
| 
						 | 
					@ -6,9 +6,15 @@
 | 
				
			||||||
        android:icon="@drawable/ic_baseline_expand_more_24"
 | 
					        android:icon="@drawable/ic_baseline_expand_more_24"
 | 
				
			||||||
        android:title="@string/expand_conversation"
 | 
					        android:title="@string/expand_conversation"
 | 
				
			||||||
        app:showAsAction="ifRoom" />
 | 
					        app:showAsAction="ifRoom" />
 | 
				
			||||||
 | 
					    <item
 | 
				
			||||||
 | 
					        android:id="@+id/action_remote"
 | 
				
			||||||
 | 
					        android:icon="@drawable/ic_baseline_location_searching_24"
 | 
				
			||||||
 | 
					        android:title="@string/display_remote_conversation"
 | 
				
			||||||
 | 
					        app:showAsAction="ifRoom" />
 | 
				
			||||||
    <item
 | 
					    <item
 | 
				
			||||||
        android:id="@+id/action_show_cw"
 | 
					        android:id="@+id/action_show_cw"
 | 
				
			||||||
        android:icon="@drawable/ic_outline_remove_red_eye_24"
 | 
					        android:icon="@drawable/ic_outline_remove_red_eye_24"
 | 
				
			||||||
        android:title="@string/expand_cw"
 | 
					        android:title="@string/expand_cw"
 | 
				
			||||||
        app:showAsAction="ifRoom" />
 | 
					        app:showAsAction="ifRoom" />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
</menu>
 | 
					</menu>
 | 
				
			||||||
| 
						 | 
					@ -2048,4 +2048,8 @@
 | 
				
			||||||
    <string name="set_custom_colors">Set custom colors</string>
 | 
					    <string name="set_custom_colors">Set custom colors</string>
 | 
				
			||||||
    <string name="light_custom_colors">Light - Custom colors</string>
 | 
					    <string name="light_custom_colors">Light - Custom colors</string>
 | 
				
			||||||
    <string name="cark_custom_colors">Dark - Custom colors</string>
 | 
					    <string name="cark_custom_colors">Dark - Custom colors</string>
 | 
				
			||||||
 | 
					    <string name="display_remote_conversation">Display remote conversation</string>
 | 
				
			||||||
 | 
					    <string name="toast_try_later">Please, try again later.</string>
 | 
				
			||||||
 | 
					    <string name="toast_on_your_instance">The conversation started on your instance!</string>
 | 
				
			||||||
 | 
					    <string name="toast_error_fetch_message">The app didn\'t find the remote message.</string>
 | 
				
			||||||
</resources>
 | 
					</resources>
 | 
				
			||||||
		Loading…
	
		Reference in a new issue