summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas <tschneider.ac@gmail.com>2024-01-12 16:19:30 +0100
committerThomas <tschneider.ac@gmail.com>2024-01-12 16:19:30 +0100
commit318b869b6a428980dd61c341a353c9aebcb1a27e (patch)
tree062abc2258d391903403a5e37094c8b3d0750663
parent336fe936e8ccbb3a96183376df0f796b546b513a (diff)
Fix hashtagscustom_intent
-rw-r--r--app/src/main/java/app/fedilab/android/mastodon/activities/HashTagActivity.java27
-rw-r--r--app/src/main/java/app/fedilab/android/mastodon/client/entities/app/CachedBundle.java20
-rw-r--r--app/src/main/java/app/fedilab/android/mastodon/helper/SpannableHelper.java34
-rw-r--r--app/src/main/java/app/fedilab/android/mastodon/viewmodel/mastodon/AccountsVM.java8
4 files changed, 67 insertions, 22 deletions
diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/HashTagActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/HashTagActivity.java
index 8cf93a411..4dd565868 100644
--- a/app/src/main/java/app/fedilab/android/mastodon/activities/HashTagActivity.java
+++ b/app/src/main/java/app/fedilab/android/mastodon/activities/HashTagActivity.java
@@ -70,17 +70,26 @@ public class HashTagActivity extends BaseActivity {
private Filter.KeywordsAttributes keyword;
private PinnedTimeline pinnedTimeline;
private Pinned pinned;
+ private ActivityHashtagBinding binding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- ActivityHashtagBinding binding = ActivityHashtagBinding.inflate(getLayoutInflater());
-
+ binding = ActivityHashtagBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
- Bundle b = getIntent().getExtras();
- if (b != null) {
- tag = b.getString(Helper.ARG_SEARCH_KEYWORD, null);
+ Bundle args = getIntent().getExtras();
+ if (args != 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)
finish();
@@ -147,10 +156,10 @@ public class HashTagActivity extends BaseActivity {
invalidateOptionsMenu();
}
- Bundle bundle = new Bundle();
- bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.TAG);
- bundle.putString(Helper.ARG_SEARCH_KEYWORD, tag);
- Helper.addFragment(getSupportFragmentManager(), R.id.nav_host_fragment_tags, new FragmentMastodonTimeline(), bundle, null, null);
+ Bundle bundleFragment = new Bundle();
+ bundleFragment.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.TAG);
+ bundleFragment.putString(Helper.ARG_SEARCH_KEYWORD, tag);
+ Helper.addFragment(getSupportFragmentManager(), R.id.nav_host_fragment_tags, new FragmentMastodonTimeline(), bundleFragment, null, null);
binding.compose.setOnClickListener(v -> {
Intent intentToot = new Intent(HashTagActivity.this, ComposeActivity.class);
StatusDraft statusDraft = new StatusDraft();
diff --git a/app/src/main/java/app/fedilab/android/mastodon/client/entities/app/CachedBundle.java b/app/src/main/java/app/fedilab/android/mastodon/client/entities/app/CachedBundle.java
index 7e438623b..e9494fb2a 100644
--- a/app/src/main/java/app/fedilab/android/mastodon/client/entities/app/CachedBundle.java
+++ b/app/src/main/java/app/fedilab/android/mastodon/client/entities/app/CachedBundle.java
@@ -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
*
diff --git a/app/src/main/java/app/fedilab/android/mastodon/helper/SpannableHelper.java b/app/src/main/java/app/fedilab/android/mastodon/helper/SpannableHelper.java
index a3b5bcc07..077136f7c 100644
--- a/app/src/main/java/app/fedilab/android/mastodon/helper/SpannableHelper.java
+++ b/app/src/main/java/app/fedilab/android/mastodon/helper/SpannableHelper.java
@@ -279,19 +279,23 @@ public class SpannableHelper {
public void onClick(@NonNull View textView) {
textView.setTag(CLICKABLE_SPAN);
Intent intent;
- Bundle b;
+ Bundle args;
if (word.startsWith("#")) {
intent = new Intent(context, HashTagActivity.class);
- b = new Bundle();
- b.putString(Helper.ARG_SEARCH_KEYWORD, word.trim());
- intent.putExtras(b);
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- context.startActivity(intent);
+ args = new Bundle();
+ args.putString(Helper.ARG_SEARCH_KEYWORD, word.trim());
+ 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);
+ });
+
} else if (word.startsWith("@")) {
intent = new Intent(context, ProfileActivity.class);
- b = new Bundle();
+ args = new Bundle();
Mention targetedMention = null;
-
for (Mention mention : mentions) {
if (word.compareToIgnoreCase("@" + mention.username) == 0) {
targetedMention = mention;
@@ -299,13 +303,17 @@ public class SpannableHelper {
}
}
if (targetedMention != null) {
- b.putString(Helper.ARG_USER_ID, targetedMention.id);
+ args.putString(Helper.ARG_USER_ID, targetedMention.id);
} else {
- b.putString(Helper.ARG_MENTION, word);
+ args.putString(Helper.ARG_MENTION, word);
}
- intent.putExtras(b);
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- 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);
+ });
}
}
diff --git a/app/src/main/java/app/fedilab/android/mastodon/viewmodel/mastodon/AccountsVM.java b/app/src/main/java/app/fedilab/android/mastodon/viewmodel/mastodon/AccountsVM.java
index 91a1856fc..ed91fe5d9 100644
--- a/app/src/main/java/app/fedilab/android/mastodon/viewmodel/mastodon/AccountsVM.java
+++ b/app/src/main/java/app/fedilab/android/mastodon/viewmodel/mastodon/AccountsVM.java
@@ -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,
* see <http://www.gnu.org/licenses>. */
+import static app.fedilab.android.BaseMainActivity.currentAccount;
+
import android.app.Application;
import android.net.Uri;
import android.os.Handler;
@@ -30,6 +32,7 @@ import java.util.List;
import app.fedilab.android.R;
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.entities.api.Account;
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.Token;
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.StatusCache;
import app.fedilab.android.mastodon.exception.DBException;
@@ -342,6 +346,7 @@ public class AccountsVM extends AndroidViewModel {
Response<Account> accountResponse = accountCall.execute();
if (accountResponse.isSuccessful()) {
account = accountResponse.body();
+ new CachedBundle(getApplication().getApplicationContext()).insertAccountBundle(account, currentAccount);
}
} catch (Exception e) {
e.printStackTrace();
@@ -1073,6 +1078,9 @@ public class AccountsVM extends AndroidViewModel {
Response<List<Account>> searchResponse = searchCall.execute();
if (searchResponse.isSuccessful()) {
accountList = searchResponse.body();
+ if(accountList != null && accountList.size() > 0 ) {
+ new CachedBundle(getApplication().getApplicationContext()).insertAccountBundle(accountList.get(0), currentAccount);
+ }
}
} catch (Exception e) {
e.printStackTrace();