Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
sk22 committed Dec 3, 2023
1 parent 0e28daa commit f4d2dbc
Show file tree
Hide file tree
Showing 20 changed files with 169 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -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<List<FollowList>>{
public GetAccountLists(String id){
super(HttpMethod.GET, "/accounts/"+id+"/lists", new TypeToken<>(){});
}
}
Original file line number Diff line number Diff line change
@@ -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<List<Account>>{
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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class UpdateAccountCredentials extends MastodonAPIRequest<Account>{
private File avatarFile, coverFile;
private List<AccountField> fields;

private Boolean discoverable, indexable;

public UpdateAccountCredentials(String displayName, String bio, Uri avatar, Uri cover, List<AccountField> fields){
super(HttpMethod.PATCH, "/accounts/update_credentials", Account.class);
this.displayName=displayName;
Expand All @@ -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()
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import com.google.gson.annotations.SerializedName;

import androidx.annotation.Keep;

@Keep
class KeywordAttribute{
public String id;
@SerializedName("_destroy")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Hashtag> {
public GetFollowedHashtags() {
public class GetFollowedTags extends HeaderPaginationRequest<Hashtag> {
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);
Expand All @@ -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+"");
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -71,6 +72,8 @@ public class AccountSession{
private transient boolean preferencesNeedSaving;
private transient AccountLocalPreferences localPreferences;

private transient List<FollowList> lists;

AccountSession(Token token, Account self, Application app, String domain, boolean activated, AccountActivationInfo activationInfo){
this.token=token;
this.self=self;
Expand Down Expand Up @@ -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<Instance> getInstance() {
return Optional.ofNullable(AccountSessionManager.getInstance().getInstanceInfo(domain));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)){
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Hashtag> result){
hashtags.addAll(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Hashtag> result){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Hashtag> hashtags) {
updateList(hashtags, hashtagsItems);
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public void onSuccess(List<FollowList> 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;
Expand Down

0 comments on commit f4d2dbc

Please sign in to comment.