Allow to check remote conversations

This commit is contained in:
Thomas 2022-12-10 10:38:01 +01:00
parent dbda1e13d2
commit a8eb33f3dd
5 changed files with 39 additions and 35 deletions

View file

@ -24,7 +24,6 @@ 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,14 +34,15 @@ import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
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;
@ -143,6 +143,8 @@ public class ContextActivity extends BaseActivity implements FragmentMastodonCon
MenuItem action_remote = menu.findItem(R.id.action_remote); MenuItem action_remote = menu.findItem(R.id.action_remote);
if (remote_instance != null) { if (remote_instance != null) {
action_remote.setVisible(false); action_remote.setVisible(false);
} else {
action_remote.setVisible(firstMessage != null && !firstMessage.visibility.equalsIgnoreCase("direct") && !firstMessage.visibility.equalsIgnoreCase("private"));
} }
return true; return true;
} }
@ -184,31 +186,31 @@ public class ContextActivity extends BaseActivity implements FragmentMastodonCon
Toasty.info(ContextActivity.this, getString(R.string.toast_on_your_instance), Toasty.LENGTH_SHORT).show(); Toasty.info(ContextActivity.this, getString(R.string.toast_on_your_instance), Toasty.LENGTH_SHORT).show();
return true; return true;
} }
Log.v(Helper.TAG, "firstMessage.uri: " + firstMessage.uri); Pattern pattern = Helper.statusIdInUrl;
Log.v(Helper.TAG, "instance: " + instance); Matcher matcher = pattern.matcher(firstMessage.uri);
CrossActionHelper.fetchStatusInRemoteInstance(ContextActivity.this, firstMessage.uri, instance, new CrossActionHelper.Callback() { String remoteId = null;
@Override if (matcher.find()) {
public void federatedStatus(Status status) { remoteId = matcher.group(1);
Log.v(Helper.TAG, ">status: " + status); }
if (remoteId != null) {
StatusesVM statusesVM = new ViewModelProvider(ContextActivity.this).get(StatusesVM.class);
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); intentContext.putExtra(Helper.ARG_STATUS, status);
intentContext.putExtra(Helper.ARG_REMOTE_INSTANCE, true); intentContext.putExtra(Helper.ARG_REMOTE_INSTANCE, instance);
intentContext.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intentContext.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intentContext); 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();
} }
}
@Override
public void federatedAccount(Account account) {
Log.v(Helper.TAG, ">account: " + account);
}
}); });
} 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();
} }
} else {
Toasty.warning(ContextActivity.this, getString(R.string.toast_error_fetch_message), Toasty.LENGTH_SHORT).show();
}
} }
return true; return true;
} }
@ -216,5 +218,6 @@ public class ContextActivity extends BaseActivity implements FragmentMastodonCon
@Override @Override
public void get(Status status) { public void get(Status status) {
firstMessage = status; firstMessage = status;
invalidateOptionsMenu();
} }
} }

View file

@ -20,7 +20,6 @@ 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;
@ -449,7 +448,6 @@ public class CrossActionHelper {
new Thread(() -> { new Thread(() -> {
Call<Results> resultsCall = mastodonSearchService.search(null, url, null, "statuses", null, null, null, null, null, null, null); Call<Results> resultsCall = mastodonSearchService.search(null, url, null, "statuses", null, null, null, null, null, null, null);
Results results = null; Results results = null;
Log.v(Helper.TAG, ">request: " + resultsCall.request());
if (resultsCall != null) { if (resultsCall != null) {
try { try {
Response<Results> resultsResponse = resultsCall.execute(); Response<Results> resultsResponse = resultsCall.execute();
@ -461,8 +459,6 @@ public class CrossActionHelper {
results.statuses = new ArrayList<>(); results.statuses = new ArrayList<>();
} }
} }
} else {
Log.v(Helper.TAG, ">err: " + resultsResponse.errorBody().string());
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
@ -471,7 +467,6 @@ public class CrossActionHelper {
Handler mainHandler = new Handler(Looper.getMainLooper()); Handler mainHandler = new Handler(Looper.getMainLooper());
Results finalResults = results; Results finalResults = results;
Runnable myRunnable = () -> { Runnable myRunnable = () -> {
Log.v(Helper.TAG, ">finalResults.statuses " + finalResults.statuses);
if (finalResults != null && finalResults.statuses != null && finalResults.statuses.size() > 0) { if (finalResults != null && finalResults.statuses != null && finalResults.statuses.size() > 0) {
callback.federatedStatus(finalResults.statuses.get(0)); callback.federatedStatus(finalResults.statuses.get(0));
} }

View file

@ -343,6 +343,8 @@ public class Helper {
public static final Pattern codePattern = Pattern.compile("code=([\\w-]+)"); public static final Pattern codePattern = Pattern.compile("code=([\\w-]+)");
public static final Pattern nitterIDPattern = Pattern.compile("/status/(\\d+)"); public static final Pattern nitterIDPattern = Pattern.compile("/status/(\\d+)");
public static final Pattern emailPattern = Pattern.compile("(\\s+[\\w_.-]+@[a-zA-Z0-9][a-zA-Z0-9.-]{1,61}[a-zA-Z0-9](?:\\.[a-zA-Z]{2,})+)"); public static final Pattern emailPattern = Pattern.compile("(\\s+[\\w_.-]+@[a-zA-Z0-9][a-zA-Z0-9.-]{1,61}[a-zA-Z0-9](?:\\.[a-zA-Z]{2,})+)");
public static final Pattern statusIdInUrl = Pattern.compile("statuses/(\\w+)");
/*public static final Pattern urlPattern = Pattern.compile( /*public static final Pattern urlPattern = Pattern.compile(
"(?i)\\b((?:[a-z][\\w-]+:(?:/{1,3}|[a-z0-9%])|www\\d{0,3}[.]|[a-z0-9.\\-]+[.][a-z]{2,10}/)(?:[^\\s()<>]+|\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\))+(?:\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\)|[^\\s`!()\\[\\]{};:'\".,<>?«»“”‘’]))", "(?i)\\b((?:[a-z][\\w-]+:(?:/{1,3}|[a-z0-9%])|www\\d{0,3}[.]|[a-z0-9.\\-]+[.][a-z]{2,10}/)(?:[^\\s()<>]+|\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\))+(?:\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\)|[^\\s`!()\\[\\]{};:'\".,<>?«»“”‘’]))",

View file

@ -1453,13 +1453,14 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
} }
return; return;
} }
if (context instanceof ContextActivity) { if (context instanceof ContextActivity && !remote) {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putSerializable(Helper.ARG_STATUS, statusToDeal); bundle.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()); 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); ((ContextActivity) context).setCurrentFragment((FragmentMastodonContext) fragment);
} else { } else {
if (remote) { if (remote) {
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();
searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.uri, null, "statuses", false, true, false, 0, null, null, 1) searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.uri, null, "statuses", false, true, false, 0, null, null, 1)
.observe((LifecycleOwner) context, results -> { .observe((LifecycleOwner) context, results -> {
@ -1472,6 +1473,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
Toasty.info(context, context.getString(R.string.toast_error_search), Toasty.LENGTH_SHORT).show(); Toasty.info(context, context.getString(R.string.toast_error_search), Toasty.LENGTH_SHORT).show();
} }
}); });
}
} else { } else {
Intent intent = new Intent(context, ContextActivity.class); Intent intent = new Intent(context, ContextActivity.class);
intent.putExtra(Helper.ARG_STATUS, statusToDeal); intent.putExtra(Helper.ARG_STATUS, statusToDeal);

View file

@ -50,6 +50,8 @@
<androidx.appcompat.widget.AppCompatTextView <androidx.appcompat.widget.AppCompatTextView
android:id="@+id/title" android:id="@+id/title"
style="@style/TextAppearance.AppCompat.Title" style="@style/TextAppearance.AppCompat.Title"
android:ellipsize="end"
android:maxLines="1"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" /> android:layout_gravity="center_vertical" />