Merge branch 'feature/favs-list' into fork
This commit is contained in:
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -536,6 +536,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.getItemId()==R.id.bookmarks);
|
item.setVisible(item.getItemId()==R.id.share || item.getItemId()==R.id.bookmarks);
|
||||||
}
|
}
|
||||||
|
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()));
|
||||||
@@ -564,6 +565,11 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
|
|||||||
args.putString("account", accountID);
|
args.putString("account", accountID);
|
||||||
args.putParcelable("profileAccount", Parcels.wrap(account));
|
args.putParcelable("profileAccount", Parcels.wrap(account));
|
||||||
Nav.go(getActivity(), BookmarksListFragment.class, args);
|
Nav.go(getActivity(), BookmarksListFragment.class, args);
|
||||||
|
}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,6 +7,7 @@
|
|||||||
<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"/>
|
||||||
<item
|
<item
|
||||||
android:id="@+id/bookmarks"
|
android:id="@+id/bookmarks"
|
||||||
android:showAsAction="always"
|
android:showAsAction="always"
|
||||||
|
|||||||
@@ -405,4 +405,5 @@
|
|||||||
<string name="check_for_update">Auf Update prüfen</string>
|
<string name="check_for_update">Auf Update prüfen</string>
|
||||||
<string name="no_update_available">Kein Update verfügbar</string>
|
<string name="no_update_available">Kein Update verfügbar</string>
|
||||||
<string name="list_timelines">Listen</string>
|
<string name="list_timelines">Listen</string>
|
||||||
|
<string name="favorited_posts">Favorisierte Beiträge</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -415,4 +415,5 @@
|
|||||||
<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="list_timelines">Lists</string>
|
<string name="list_timelines">Lists</string>
|
||||||
|
<string name="favorited_posts">Favorited posts</string>
|
||||||
</resources>
|
</resources>
|
||||||
Reference in New Issue
Block a user