@@ -0,0 +1,49 @@
|
|||||||
|
package org.joinmastodon.android.api.requests.accounts;
|
||||||
|
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
|
||||||
|
import org.joinmastodon.android.api.MastodonAPIRequest;
|
||||||
|
import org.joinmastodon.android.model.Status;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import okhttp3.Response;
|
||||||
|
|
||||||
|
public class GetFavourites extends MastodonAPIRequest<List<Status>>{
|
||||||
|
private String maxId;
|
||||||
|
|
||||||
|
public GetFavourites(String maxID, String minID, int limit){
|
||||||
|
super(HttpMethod.GET, "/favourites", new TypeToken<>(){});
|
||||||
|
if(maxID!=null)
|
||||||
|
addQueryParameter("max_id", maxID);
|
||||||
|
if(minID!=null)
|
||||||
|
addQueryParameter("min_id", minID);
|
||||||
|
if(limit>0)
|
||||||
|
addQueryParameter("limit", ""+limit);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void validateAndPostprocessResponse(List<Status> respObj, Response httpResponse) throws IOException {
|
||||||
|
super.validateAndPostprocessResponse(respObj, httpResponse);
|
||||||
|
// <https://mastodon.social/api/v1/bookmarks?max_id=268962>; rel="next",
|
||||||
|
// <https://mastodon.social/api/v1/bookmarks?min_id=268981>; rel="prev"
|
||||||
|
String link=httpResponse.header("link");
|
||||||
|
// parsing link header by hand; using a library would be cleaner
|
||||||
|
// (also, the functionality should be part of the max id logics and implemented in MastodonAPIRequest)
|
||||||
|
if(link==null) return;
|
||||||
|
String maxIdEq="max_id=";
|
||||||
|
for(String s : link.split(",")) {
|
||||||
|
if(s.contains("rel=\"next\"")) {
|
||||||
|
int start=s.indexOf(maxIdEq)+maxIdEq.length();
|
||||||
|
int end=s.indexOf('>');
|
||||||
|
if(start<0 || start>end) return;
|
||||||
|
this.maxId=s.substring(start, end);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMaxId() {
|
||||||
|
return maxId;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package org.joinmastodon.android.fragments;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import org.joinmastodon.android.R;
|
||||||
|
import org.joinmastodon.android.api.requests.accounts.GetFavourites;
|
||||||
|
import org.joinmastodon.android.api.session.AccountSession;
|
||||||
|
import org.joinmastodon.android.api.session.AccountSessionManager;
|
||||||
|
import org.joinmastodon.android.model.Status;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import me.grishka.appkit.api.SimpleCallback;
|
||||||
|
|
||||||
|
public class FavoritesListFragment extends StatusListFragment{
|
||||||
|
|
||||||
|
private String accountID;
|
||||||
|
private String lastMaxId=null;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState){
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
accountID=getArguments().getString("account");
|
||||||
|
AccountSession session=AccountSessionManager.getInstance().getAccount(accountID);
|
||||||
|
setTitle(R.string.favorited_posts);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onShown(){
|
||||||
|
super.onShown();
|
||||||
|
if(!getArguments().getBoolean("noAutoLoad") && !loaded && !dataLoading)
|
||||||
|
loadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doLoadData(int offset, int count) {
|
||||||
|
GetFavourites b=new GetFavourites(offset>0 ? lastMaxId : null, null, count);
|
||||||
|
currentRequest=b.setCallback(new SimpleCallback<>(this){
|
||||||
|
@Override
|
||||||
|
public void onSuccess(List<Status> result){
|
||||||
|
onDataLoaded(result, b.getMaxId()!=null);
|
||||||
|
lastMaxId=b.getMaxId();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.exec(accountID);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -526,6 +526,7 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
|
|||||||
MenuItem item=menu.getItem(i);
|
MenuItem item=menu.getItem(i);
|
||||||
item.setVisible(item.getItemId()==R.id.share);
|
item.setVisible(item.getItemId()==R.id.share);
|
||||||
}
|
}
|
||||||
|
menu.findItem(R.id.favorites_list).setVisible(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
menu.findItem(R.id.mute).setTitle(getString(relationship.muting ? R.string.unmute_user : R.string.mute_user, account.getDisplayUsername()));
|
menu.findItem(R.id.mute).setTitle(getString(relationship.muting ? R.string.unmute_user : R.string.mute_user, account.getDisplayUsername()));
|
||||||
@@ -549,6 +550,11 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
|
|||||||
intent.setType("text/plain");
|
intent.setType("text/plain");
|
||||||
intent.putExtra(Intent.EXTRA_TEXT, account.url);
|
intent.putExtra(Intent.EXTRA_TEXT, account.url);
|
||||||
startActivity(Intent.createChooser(intent, item.getTitle()));
|
startActivity(Intent.createChooser(intent, item.getTitle()));
|
||||||
|
}else if(id==R.id.favorites_list) {
|
||||||
|
Bundle args=new Bundle();
|
||||||
|
args.putString("account", accountID);
|
||||||
|
args.putParcelable("profileAccount", Parcels.wrap(account));
|
||||||
|
Nav.go(getActivity(), FavoritesListFragment.class, args);
|
||||||
}else if(id==R.id.mute){
|
}else if(id==R.id.mute){
|
||||||
confirmToggleMuted();
|
confirmToggleMuted();
|
||||||
}else if(id==R.id.block){
|
}else if(id==R.id.block){
|
||||||
|
|||||||
@@ -7,4 +7,5 @@
|
|||||||
<item android:id="@+id/block_domain" android:title="@string/block_domain"/>
|
<item android:id="@+id/block_domain" android:title="@string/block_domain"/>
|
||||||
<item android:id="@+id/hide_boosts" android:title="@string/hide_boosts_from_user"/>
|
<item android:id="@+id/hide_boosts" android:title="@string/hide_boosts_from_user"/>
|
||||||
<item android:id="@+id/open_in_browser" android:title="@string/open_in_browser"/>
|
<item android:id="@+id/open_in_browser" android:title="@string/open_in_browser"/>
|
||||||
|
<item android:id="@+id/favorites_list" android:title="@string/favorited_posts" android:visible="false"/>
|
||||||
</menu>
|
</menu>
|
||||||
@@ -377,4 +377,5 @@
|
|||||||
<!-- %s is file size -->
|
<!-- %s is file size -->
|
||||||
<string name="download_update">Download (%s)</string>
|
<string name="download_update">Download (%s)</string>
|
||||||
<string name="install_update">Installieren</string>
|
<string name="install_update">Installieren</string>
|
||||||
|
<string name="favorited_posts">Favorisierte Beiträge</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -387,4 +387,5 @@
|
|||||||
<string name="privacy_policy_title">Mastodon and your privacy</string>
|
<string name="privacy_policy_title">Mastodon and your privacy</string>
|
||||||
<string name="privacy_policy_subtitle">Although the Mastodon app does not collect any data, the server you sign up through may have a different policy. Take a minute to review and agree to the Mastodon app privacy policy and your server\'s privacy policy.</string>
|
<string name="privacy_policy_subtitle">Although the Mastodon app does not collect any data, the server you sign up through may have a different policy. Take a minute to review and agree to the Mastodon app privacy policy and your server\'s privacy policy.</string>
|
||||||
<string name="i_agree">I Agree</string>
|
<string name="i_agree">I Agree</string>
|
||||||
|
<string name="favorited_posts">Favorited posts</string>
|
||||||
</resources>
|
</resources>
|
||||||
Reference in New Issue
Block a user