diff --git a/mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/GetAccountLists.java b/mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/GetAccountLists.java new file mode 100644 index 0000000000..55e03fb319 --- /dev/null +++ b/mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/GetAccountLists.java @@ -0,0 +1,14 @@ +package org.joinmastodon.android.api.requests.accounts; + +import com.google.gson.reflect.TypeToken; + +import org.joinmastodon.android.api.MastodonAPIRequest; +import org.joinmastodon.android.model.FollowList; + +import java.util.List; + +public class GetAccountLists extends MastodonAPIRequest>{ + public GetAccountLists(String id){ + super(HttpMethod.GET, "/accounts/"+id+"/lists", new TypeToken<>(){}); + } +} diff --git a/mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/SearchAccounts.java b/mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/SearchAccounts.java new file mode 100644 index 0000000000..6bfb87e4ce --- /dev/null +++ b/mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/SearchAccounts.java @@ -0,0 +1,23 @@ +package org.joinmastodon.android.api.requests.accounts; + +import com.google.gson.reflect.TypeToken; + +import org.joinmastodon.android.api.MastodonAPIRequest; +import org.joinmastodon.android.model.Account; + +import java.util.List; + +public class SearchAccounts extends MastodonAPIRequest>{ + public SearchAccounts(String q, int limit, int offset, boolean resolve, boolean following){ + super(HttpMethod.GET, "/accounts/search", new TypeToken<>(){}); + addQueryParameter("q", q); + if(limit>0) + addQueryParameter("limit", limit+""); + if(offset>0) + addQueryParameter("offset", offset+""); + if(resolve) + addQueryParameter("resolve", "true"); + if(following) + addQueryParameter("following", "true"); + } +} diff --git a/mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/UpdateAccountCredentials.java b/mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/UpdateAccountCredentials.java index 5724a933be..fa2e008b46 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/UpdateAccountCredentials.java +++ b/mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/UpdateAccountCredentials.java @@ -23,6 +23,8 @@ public class UpdateAccountCredentials extends MastodonAPIRequest{ private File avatarFile, coverFile; private List fields; + private Boolean discoverable, indexable; + public UpdateAccountCredentials(String displayName, String bio, Uri avatar, Uri cover, List fields){ super(HttpMethod.PATCH, "/accounts/update_credentials", Account.class); this.displayName=displayName; @@ -41,6 +43,12 @@ public UpdateAccountCredentials(String displayName, String bio, File avatar, Fil this.fields=fields; } + public UpdateAccountCredentials setDiscoverableIndexable(boolean discoverable, boolean indexable){ + this.discoverable=discoverable; + this.indexable=indexable; + return this; + } + @Override public RequestBody getRequestBody() throws IOException{ MultipartBody.Builder bldr=new MultipartBody.Builder() @@ -58,15 +66,21 @@ public RequestBody getRequestBody() throws IOException{ }else if(coverFile!=null){ bldr.addFormDataPart("header", coverFile.getName(), new ResizedImageRequestBody(Uri.fromFile(coverFile), 1500*500, null)); } - if(fields.isEmpty()){ - bldr.addFormDataPart("fields_attributes[0][name]", "").addFormDataPart("fields_attributes[0][value]", ""); - }else{ - int i=0; - for(AccountField field:fields){ - bldr.addFormDataPart("fields_attributes["+i+"][name]", field.name).addFormDataPart("fields_attributes["+i+"][value]", field.value); - i++; + if(fields!=null){ + if(fields.isEmpty()){ + bldr.addFormDataPart("fields_attributes[0][name]", "").addFormDataPart("fields_attributes[0][value]", ""); + }else{ + int i=0; + for(AccountField field:fields){ + bldr.addFormDataPart("fields_attributes["+i+"][name]", field.name).addFormDataPart("fields_attributes["+i+"][value]", field.value); + i++; + } } } + if(discoverable!=null) + bldr.addFormDataPart("discoverable", discoverable.toString()); + if(indexable!=null) + bldr.addFormDataPart("indexable", indexable.toString()); return bldr.build(); } diff --git a/mastodon/src/main/java/org/joinmastodon/android/api/requests/filters/KeywordAttribute.java b/mastodon/src/main/java/org/joinmastodon/android/api/requests/filters/KeywordAttribute.java index d35a0f0fac..b2ed7f18b6 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/api/requests/filters/KeywordAttribute.java +++ b/mastodon/src/main/java/org/joinmastodon/android/api/requests/filters/KeywordAttribute.java @@ -2,6 +2,9 @@ import com.google.gson.annotations.SerializedName; +import androidx.annotation.Keep; + +@Keep class KeywordAttribute{ public String id; @SerializedName("_destroy") diff --git a/mastodon/src/main/java/org/joinmastodon/android/api/requests/tags/GetFollowedHashtags.java b/mastodon/src/main/java/org/joinmastodon/android/api/requests/tags/GetFollowedTags.java similarity index 63% rename from mastodon/src/main/java/org/joinmastodon/android/api/requests/tags/GetFollowedHashtags.java rename to mastodon/src/main/java/org/joinmastodon/android/api/requests/tags/GetFollowedTags.java index b347fe2357..7a6d6d1ef3 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/api/requests/tags/GetFollowedHashtags.java +++ b/mastodon/src/main/java/org/joinmastodon/android/api/requests/tags/GetFollowedTags.java @@ -2,18 +2,19 @@ import com.google.gson.reflect.TypeToken; -import org.joinmastodon.android.api.MastodonAPIRequest; import org.joinmastodon.android.api.requests.HeaderPaginationRequest; import org.joinmastodon.android.model.Hashtag; -import java.util.List; - -public class GetFollowedHashtags extends HeaderPaginationRequest { - public GetFollowedHashtags() { +public class GetFollowedTags extends HeaderPaginationRequest { + public GetFollowedTags() { this(null, null, -1, null); } - public GetFollowedHashtags(String maxID, String minID, int limit, String sinceID){ + public GetFollowedTags(String maxID, int limit){ + this(maxID, null, limit, null); + } + + public GetFollowedTags(String maxID, String minID, int limit, String sinceID){ super(HttpMethod.GET, "/followed_tags", new TypeToken<>(){}); if(maxID!=null) addQueryParameter("max_id", maxID); @@ -22,7 +23,7 @@ public GetFollowedHashtags(String maxID, String minID, int limit, String sinceID if(sinceID!=null) addQueryParameter("since_id", sinceID); if(limit>0) - addQueryParameter("limit", ""+limit); + addQueryParameter("limit", limit+""); } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/api/requests/timelines/GetListTimeline.java b/mastodon/src/main/java/org/joinmastodon/android/api/requests/timelines/GetListTimeline.java index 29dfb67ac8..c10de2cb50 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/api/requests/timelines/GetListTimeline.java +++ b/mastodon/src/main/java/org/joinmastodon/android/api/requests/timelines/GetListTimeline.java @@ -18,7 +18,7 @@ public GetListTimeline(String listID, String maxID, String minID, int limit, Str addQueryParameter("limit", ""+limit); if(sinceID!=null) addQueryParameter("since_id", sinceID); - if(replyVisibility != null) + if(replyVisibility!=null) addQueryParameter("reply_visibility", replyVisibility); } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountSession.java b/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountSession.java index 5d70e0b236..5cf85075d1 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountSession.java +++ b/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountSession.java @@ -25,6 +25,7 @@ import org.joinmastodon.android.model.FilterAction; import org.joinmastodon.android.model.FilterContext; import org.joinmastodon.android.model.FilterResult; +import org.joinmastodon.android.model.FollowList; import org.joinmastodon.android.model.Instance; import org.joinmastodon.android.model.LegacyFilter; import org.joinmastodon.android.model.Preferences; @@ -71,6 +72,8 @@ public class AccountSession{ private transient boolean preferencesNeedSaving; private transient AccountLocalPreferences localPreferences; + private transient List lists; + AccountSession(Token token, Account self, Application app, String domain, boolean activated, AccountActivationInfo activationInfo){ this.token=token; this.self=self; @@ -327,6 +330,14 @@ public void updateAccountInfo(){ AccountSessionManager.getInstance().updateSessionLocalInfo(this); } + public boolean isNotificationsMentionsOnly(){ + return getRawLocalPreferences().getBoolean("notificationsMentionsOnly", false); + } + + public void setNotificationsMentionsOnly(boolean mentionsOnly){ + getRawLocalPreferences().edit().putBoolean("notificationsMentionsOnly", mentionsOnly).apply(); + } + public Optional getInstance() { return Optional.ofNullable(AccountSessionManager.getInstance().getInstanceInfo(domain)); } diff --git a/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountSessionManager.java b/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountSessionManager.java index cd959a85ae..550c959a75 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountSessionManager.java +++ b/mastodon/src/main/java/org/joinmastodon/android/api/session/AccountSessionManager.java @@ -205,12 +205,17 @@ public void setLastActiveAccountID(String id){ public void removeAccount(String id){ AccountSession session=getAccount(id); session.getCacheController().closeDatabase(); + session.getCacheController().getListsFile().delete(); MastodonApp.context.deleteDatabase(id+".db"); MastodonApp.context.getSharedPreferences(id, 0).edit().clear().commit(); if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.N){ MastodonApp.context.deleteSharedPreferences(id); }else{ - new File(MastodonApp.context.getDir("shared_prefs", Context.MODE_PRIVATE), id+".xml").delete(); + String dataDir=MastodonApp.context.getApplicationInfo().dataDir; + if(dataDir!=null){ + File prefsDir=new File(dataDir, "shared_prefs"); + new File(prefsDir, id+".xml").delete(); + } } sessions.remove(id); if(lastActiveAccountID.equals(id)){ diff --git a/mastodon/src/main/java/org/joinmastodon/android/events/AccountAddedToListEvent.java b/mastodon/src/main/java/org/joinmastodon/android/events/AccountAddedToListEvent.java new file mode 100644 index 0000000000..0324853814 --- /dev/null +++ b/mastodon/src/main/java/org/joinmastodon/android/events/AccountAddedToListEvent.java @@ -0,0 +1,15 @@ +package org.joinmastodon.android.events; + +import org.joinmastodon.android.model.Account; + +public class AccountAddedToListEvent{ + public final String accountID; + public final String listID; + public final Account account; + + public AccountAddedToListEvent(String accountID, String listID, Account account){ + this.accountID=accountID; + this.listID=listID; + this.account=account; + } +} diff --git a/mastodon/src/main/java/org/joinmastodon/android/events/AccountRemovedFromListEvent.java b/mastodon/src/main/java/org/joinmastodon/android/events/AccountRemovedFromListEvent.java new file mode 100644 index 0000000000..f7cce08e74 --- /dev/null +++ b/mastodon/src/main/java/org/joinmastodon/android/events/AccountRemovedFromListEvent.java @@ -0,0 +1,13 @@ +package org.joinmastodon.android.events; + +public class AccountRemovedFromListEvent{ + public final String accountID; + public final String listID; + public final String targetAccountID; + + public AccountRemovedFromListEvent(String accountID, String listID, String targetAccountID){ + this.accountID=accountID; + this.listID=listID; + this.targetAccountID=targetAccountID; + } +} diff --git a/mastodon/src/main/java/org/joinmastodon/android/events/FinishListCreationFragmentEvent.java b/mastodon/src/main/java/org/joinmastodon/android/events/FinishListCreationFragmentEvent.java new file mode 100644 index 0000000000..ec7a33346b --- /dev/null +++ b/mastodon/src/main/java/org/joinmastodon/android/events/FinishListCreationFragmentEvent.java @@ -0,0 +1,11 @@ +package org.joinmastodon.android.events; + +public class FinishListCreationFragmentEvent{ + public final String accountID; + public final String listID; + + public FinishListCreationFragmentEvent(String accountID, String listID){ + this.accountID=accountID; + this.listID=listID; + } +} diff --git a/mastodon/src/main/java/org/joinmastodon/android/events/ListCreatedEvent.java b/mastodon/src/main/java/org/joinmastodon/android/events/ListCreatedEvent.java new file mode 100644 index 0000000000..00de72dcc0 --- /dev/null +++ b/mastodon/src/main/java/org/joinmastodon/android/events/ListCreatedEvent.java @@ -0,0 +1,13 @@ +package org.joinmastodon.android.events; + +import org.joinmastodon.android.model.FollowList; + +public class ListCreatedEvent{ + public final String accountID; + public final FollowList list; + + public ListCreatedEvent(String accountID, FollowList list){ + this.accountID=accountID; + this.list=list; + } +} diff --git a/mastodon/src/main/java/org/joinmastodon/android/events/ListDeletedEvent.java b/mastodon/src/main/java/org/joinmastodon/android/events/ListDeletedEvent.java index 9824bb233f..b12eaa2228 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/events/ListDeletedEvent.java +++ b/mastodon/src/main/java/org/joinmastodon/android/events/ListDeletedEvent.java @@ -1,9 +1,11 @@ package org.joinmastodon.android.events; -public class ListDeletedEvent { - public final String id; +public class ListDeletedEvent{ + public final String accountID; + public final String listID; - public ListDeletedEvent(String id) { - this.id = id; + public ListDeletedEvent(String accountID, String listID){ + this.accountID=accountID; + this.listID=listID; } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/events/ListUpdatedCreatedEvent.java b/mastodon/src/main/java/org/joinmastodon/android/events/ListUpdatedCreatedEvent.java index 919a2950a0..2eab706414 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/events/ListUpdatedCreatedEvent.java +++ b/mastodon/src/main/java/org/joinmastodon/android/events/ListUpdatedCreatedEvent.java @@ -2,6 +2,7 @@ import org.joinmastodon.android.model.FollowList; +// TODO: replace with ListCreatedEvent/ListUpdatedEvent public class ListUpdatedCreatedEvent { public final String id; public final String title; diff --git a/mastodon/src/main/java/org/joinmastodon/android/events/ListUpdatedEvent.java b/mastodon/src/main/java/org/joinmastodon/android/events/ListUpdatedEvent.java new file mode 100644 index 0000000000..b27fe0142e --- /dev/null +++ b/mastodon/src/main/java/org/joinmastodon/android/events/ListUpdatedEvent.java @@ -0,0 +1,13 @@ +package org.joinmastodon.android.events; + +import org.joinmastodon.android.model.FollowList; + +public class ListUpdatedEvent{ + public final String accountID; + public final FollowList list; + + public ListUpdatedEvent(String accountID, FollowList list){ + this.accountID=accountID; + this.list=list; + } +} diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/EditTimelinesFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/EditTimelinesFragment.java index 0a10ef03c3..656a4066dd 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/EditTimelinesFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/EditTimelinesFragment.java @@ -36,7 +36,7 @@ import org.joinmastodon.android.R; import org.joinmastodon.android.api.requests.lists.GetLists; -import org.joinmastodon.android.api.requests.tags.GetFollowedHashtags; +import org.joinmastodon.android.api.requests.tags.GetFollowedTags; import org.joinmastodon.android.api.session.AccountLocalPreferences; import org.joinmastodon.android.api.session.AccountSessionManager; import org.joinmastodon.android.model.FollowList; @@ -97,7 +97,7 @@ public void onError(ErrorResponse error){ } }).exec(accountID); - new GetFollowedHashtags().setCallback(new Callback<>(){ + new GetFollowedTags().setCallback(new Callback<>(){ @Override public void onSuccess(HeaderPaginationList result){ hashtags.addAll(result); diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/FollowedHashtagsFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/FollowedHashtagsFragment.java index ccb86fdc5a..93b4fe3c40 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/FollowedHashtagsFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/FollowedHashtagsFragment.java @@ -10,7 +10,7 @@ import androidx.recyclerview.widget.RecyclerView; import org.joinmastodon.android.R; -import org.joinmastodon.android.api.requests.tags.GetFollowedHashtags; +import org.joinmastodon.android.api.requests.tags.GetFollowedTags; import org.joinmastodon.android.model.Hashtag; import org.joinmastodon.android.model.HeaderPaginationList; import org.joinmastodon.android.ui.DividerItemDecoration; @@ -52,7 +52,7 @@ public void onViewCreated(View view, Bundle savedInstanceState) { @Override protected void doLoadData(int offset, int count){ - currentRequest=new GetFollowedHashtags(offset==0 ? null : nextMaxID, null, count, null) + currentRequest=new GetFollowedTags(offset==0 ? null : nextMaxID, null, count, null) .setCallback(new SimpleCallback<>(this){ @Override public void onSuccess(HeaderPaginationList result){ diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTabFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTabFragment.java index 6911c09460..4f0e0aed38 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTabFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTabFragment.java @@ -43,11 +43,12 @@ import org.joinmastodon.android.R; import org.joinmastodon.android.api.requests.announcements.GetAnnouncements; import org.joinmastodon.android.api.requests.lists.GetLists; -import org.joinmastodon.android.api.requests.tags.GetFollowedHashtags; +import org.joinmastodon.android.api.requests.tags.GetFollowedTags; import org.joinmastodon.android.api.session.AccountSessionManager; import org.joinmastodon.android.events.HashtagUpdatedEvent; import org.joinmastodon.android.events.ListDeletedEvent; import org.joinmastodon.android.events.ListUpdatedCreatedEvent; +import org.joinmastodon.android.events.ListUpdatedEvent; import org.joinmastodon.android.events.SelfUpdateStateChangedEvent; import org.joinmastodon.android.fragments.settings.SettingsMainFragment; import org.joinmastodon.android.model.Announcement; @@ -276,7 +277,7 @@ public void onError(ErrorResponse error) { } }).exec(accountID); - new GetFollowedHashtags().setCallback(new Callback<>() { + new GetFollowedTags().setCallback(new Callback<>() { @Override public void onSuccess(HeaderPaginationList hashtags) { updateList(hashtags, hashtagsItems); @@ -691,7 +692,7 @@ public void onHashtagUpdatedEvent(HashtagUpdatedEvent event) { @Subscribe public void onListDeletedEvent(ListDeletedEvent event) { - handleListEvent(listItems, l -> l.id.equals(event.id), false, null); + handleListEvent(listItems, l -> l.id.equals(event.listID), false, null); } @Subscribe diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/ListTimelineFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/ListTimelineFragment.java index a55db5b8f6..514566874d 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ListTimelineFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ListTimelineFragment.java @@ -119,7 +119,7 @@ public void onError(ErrorResponse error) { .show(); } else if (item.getItemId() == R.id.delete) { UiUtils.confirmDeleteList(getActivity(), accountID, listID, listTitle, () -> { - E.post(new ListDeletedEvent(listID)); + E.post(new ListDeletedEvent(accountID, listID)); Nav.finish(this); }); } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/ListsFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/ListsFragment.java index dcf7b6f853..1edabac667 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ListsFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ListsFragment.java @@ -171,7 +171,7 @@ public void onSuccess(List allLists) { public void onListDeletedEvent(ListDeletedEvent event) { for (int i = 0; i < data.size(); i++) { FollowList item = data.get(i); - if (item.id.equals(event.id)) { + if (item.id.equals(event.listID)) { data.remove(i); adapter.notifyItemRemoved(i); break;