Fix hashtags

This commit is contained in:
Thomas 2024-01-12 16:19:30 +01:00
parent 336fe936e8
commit 318b869b6a
4 changed files with 67 additions and 22 deletions

View file

@ -70,17 +70,26 @@ public class HashTagActivity extends BaseActivity {
private Filter.KeywordsAttributes keyword; private Filter.KeywordsAttributes keyword;
private PinnedTimeline pinnedTimeline; private PinnedTimeline pinnedTimeline;
private Pinned pinned; private Pinned pinned;
private ActivityHashtagBinding binding;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
ActivityHashtagBinding binding = ActivityHashtagBinding.inflate(getLayoutInflater()); binding = ActivityHashtagBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot()); setContentView(binding.getRoot());
Bundle b = getIntent().getExtras(); Bundle args = getIntent().getExtras();
if (b != null) { if (args != null) {
tag = b.getString(Helper.ARG_SEARCH_KEYWORD, null); long bundleId = args.getLong(Helper.ARG_INTENT_ID, -1);
new CachedBundle(HashTagActivity.this).getBundle(bundleId, currentAccount, this::initializeAfterBundle);
} else {
initializeAfterBundle(null);
}
}
private void initializeAfterBundle(Bundle bundle) {
if( bundle != null) {
tag = bundle.getString(Helper.ARG_SEARCH_KEYWORD, null);
} }
if (tag == null) if (tag == null)
finish(); finish();
@ -147,10 +156,10 @@ public class HashTagActivity extends BaseActivity {
invalidateOptionsMenu(); invalidateOptionsMenu();
} }
Bundle bundle = new Bundle(); Bundle bundleFragment = new Bundle();
bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.TAG); bundleFragment.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.TAG);
bundle.putString(Helper.ARG_SEARCH_KEYWORD, tag); bundleFragment.putString(Helper.ARG_SEARCH_KEYWORD, tag);
Helper.addFragment(getSupportFragmentManager(), R.id.nav_host_fragment_tags, new FragmentMastodonTimeline(), bundle, null, null); Helper.addFragment(getSupportFragmentManager(), R.id.nav_host_fragment_tags, new FragmentMastodonTimeline(), bundleFragment, null, null);
binding.compose.setOnClickListener(v -> { binding.compose.setOnClickListener(v -> {
Intent intentToot = new Intent(HashTagActivity.this, ComposeActivity.class); Intent intentToot = new Intent(HashTagActivity.this, ComposeActivity.class);
StatusDraft statusDraft = new StatusDraft(); StatusDraft statusDraft = new StatusDraft();

View file

@ -68,6 +68,26 @@ public class CachedBundle {
} }
public long insertAccountBundle(Account account, BaseAccount currentUser) throws DBException {
if (db == null) {
throw new DBException("db is null. Wrong initialization.");
}
ContentValues valuesAccount = new ContentValues();
Bundle bundleAccount = new Bundle();
if (account != null) {
bundleAccount.putSerializable(Helper.ARG_ACCOUNT, account);
valuesAccount.put(Sqlite.COL_BUNDLE, serializeBundle(bundleAccount));
valuesAccount.put(Sqlite.COL_CREATED_AT, Helper.dateToString(new Date()));
valuesAccount.put(Sqlite.COL_TARGET_ID, account.id);
valuesAccount.put(Sqlite.COL_USER_ID, currentUser.user_id);
valuesAccount.put(Sqlite.COL_INSTANCE, currentUser.instance);
valuesAccount.put(Sqlite.COL_TYPE, CacheType.ACCOUNT.getValue());
removeIntent(currentUser, account.id);
return db.insertOrThrow(Sqlite.TABLE_INTENT, null, valuesAccount);
}
return -1;
}
/** /**
* Insert a bundle in db * Insert a bundle in db
* *

View file

@ -279,19 +279,23 @@ public class SpannableHelper {
public void onClick(@NonNull View textView) { public void onClick(@NonNull View textView) {
textView.setTag(CLICKABLE_SPAN); textView.setTag(CLICKABLE_SPAN);
Intent intent; Intent intent;
Bundle b; Bundle args;
if (word.startsWith("#")) { if (word.startsWith("#")) {
intent = new Intent(context, HashTagActivity.class); intent = new Intent(context, HashTagActivity.class);
b = new Bundle(); args = new Bundle();
b.putString(Helper.ARG_SEARCH_KEYWORD, word.trim()); args.putString(Helper.ARG_SEARCH_KEYWORD, word.trim());
intent.putExtras(b); new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Bundle bundle = new Bundle();
context.startActivity(intent); bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
});
} else if (word.startsWith("@")) { } else if (word.startsWith("@")) {
intent = new Intent(context, ProfileActivity.class); intent = new Intent(context, ProfileActivity.class);
b = new Bundle(); args = new Bundle();
Mention targetedMention = null; Mention targetedMention = null;
for (Mention mention : mentions) { for (Mention mention : mentions) {
if (word.compareToIgnoreCase("@" + mention.username) == 0) { if (word.compareToIgnoreCase("@" + mention.username) == 0) {
targetedMention = mention; targetedMention = mention;
@ -299,13 +303,17 @@ public class SpannableHelper {
} }
} }
if (targetedMention != null) { if (targetedMention != null) {
b.putString(Helper.ARG_USER_ID, targetedMention.id); args.putString(Helper.ARG_USER_ID, targetedMention.id);
} else { } else {
b.putString(Helper.ARG_MENTION, word); args.putString(Helper.ARG_MENTION, word);
} }
intent.putExtras(b); new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Bundle bundle = new Bundle();
context.startActivity(intent); bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
});
} }
} }

View file

@ -14,6 +14,8 @@ package app.fedilab.android.mastodon.viewmodel.mastodon;
* 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.Application; import android.app.Application;
import android.net.Uri; import android.net.Uri;
import android.os.Handler; import android.os.Handler;
@ -30,6 +32,7 @@ import java.util.List;
import app.fedilab.android.R; import app.fedilab.android.R;
import app.fedilab.android.activities.MainActivity; import app.fedilab.android.activities.MainActivity;
import app.fedilab.android.mastodon.activities.ProfileActivity;
import app.fedilab.android.mastodon.client.endpoints.MastodonAccountsService; import app.fedilab.android.mastodon.client.endpoints.MastodonAccountsService;
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.Accounts; import app.fedilab.android.mastodon.client.entities.api.Accounts;
@ -52,6 +55,7 @@ import app.fedilab.android.mastodon.client.entities.api.Suggestions;
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.api.Token; import app.fedilab.android.mastodon.client.entities.api.Token;
import app.fedilab.android.mastodon.client.entities.app.BaseAccount; import app.fedilab.android.mastodon.client.entities.app.BaseAccount;
import app.fedilab.android.mastodon.client.entities.app.CachedBundle;
import app.fedilab.android.mastodon.client.entities.app.MutedAccounts; import app.fedilab.android.mastodon.client.entities.app.MutedAccounts;
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;
@ -342,6 +346,7 @@ public class AccountsVM extends AndroidViewModel {
Response<Account> accountResponse = accountCall.execute(); Response<Account> accountResponse = accountCall.execute();
if (accountResponse.isSuccessful()) { if (accountResponse.isSuccessful()) {
account = accountResponse.body(); account = accountResponse.body();
new CachedBundle(getApplication().getApplicationContext()).insertAccountBundle(account, currentAccount);
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -1073,6 +1078,9 @@ public class AccountsVM extends AndroidViewModel {
Response<List<Account>> searchResponse = searchCall.execute(); Response<List<Account>> searchResponse = searchCall.execute();
if (searchResponse.isSuccessful()) { if (searchResponse.isSuccessful()) {
accountList = searchResponse.body(); accountList = searchResponse.body();
if(accountList != null && accountList.size() > 0 ) {
new CachedBundle(getApplication().getApplicationContext()).insertAccountBundle(accountList.get(0), currentAccount);
}
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();