Prepares fetch more toots with bookmark
This commit is contained in:
parent
0e0e850e77
commit
665f14388f
|
@ -141,6 +141,8 @@ public abstract class BaseMainActivity extends AppCompatActivity
|
|||
String show_filtered;
|
||||
private AppBarLayout appBar;
|
||||
private static boolean activityPaused;
|
||||
private String bookmark;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -572,6 +574,8 @@ public abstract class BaseMainActivity extends AppCompatActivity
|
|||
});
|
||||
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
//Get the previous bookmark value
|
||||
bookmark = sharedpreferences.getString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, null);
|
||||
Account account = new AccountDAO(getApplicationContext(), db).getAccountByID(userId);
|
||||
if( account == null){
|
||||
Helper.logout(getApplicationContext());
|
||||
|
@ -1394,6 +1398,14 @@ public abstract class BaseMainActivity extends AppCompatActivity
|
|||
Helper.canPin = (currentVersion.compareTo(minVersion) == 1 || currentVersion.equals(minVersion));
|
||||
}
|
||||
|
||||
public String getBookmark() {
|
||||
return bookmark;
|
||||
}
|
||||
|
||||
public void setBookmark(String bookmark) {
|
||||
this.bookmark = bookmark;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Page Adapter for settings
|
||||
|
|
|
@ -93,6 +93,7 @@ public class Status implements Parcelable {
|
|||
private boolean isNew = false;
|
||||
private boolean isTakingScreenShot = false;
|
||||
private boolean isVisible = true;
|
||||
private boolean fetchMore = false;
|
||||
private Status status;
|
||||
private String content, contentCW, contentTranslated;
|
||||
private SpannableString contentSpan, contentSpanCW, contentSpanTranslated;
|
||||
|
@ -732,4 +733,12 @@ public class Status implements Parcelable {
|
|||
public void setEmojiTranslateFound(boolean emojiTranslateFound) {
|
||||
isEmojiTranslateFound = emojiTranslateFound;
|
||||
}
|
||||
|
||||
public boolean isFetchMore() {
|
||||
return fetchMore;
|
||||
}
|
||||
|
||||
public void setFetchMore(boolean fetchMore) {
|
||||
this.fetchMore = fetchMore;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,6 +71,7 @@ import java.util.regex.Matcher;
|
|||
import java.util.regex.Pattern;
|
||||
|
||||
import fr.gouv.etalab.mastodon.R;
|
||||
import fr.gouv.etalab.mastodon.activities.BaseMainActivity;
|
||||
import fr.gouv.etalab.mastodon.activities.MediaActivity;
|
||||
import fr.gouv.etalab.mastodon.activities.ShowAccountActivity;
|
||||
import fr.gouv.etalab.mastodon.activities.ShowConversationActivity;
|
||||
|
@ -114,6 +115,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
private final int DISPLAYED_STATUS = 1;
|
||||
private List<Status> pins;
|
||||
private int conversationPosition;
|
||||
private String bookmark = null;
|
||||
|
||||
public StatusListAdapter(Context context, RetrieveFeedsAsyncTask.Type type, String targetedId, boolean isOnWifi, int behaviorWithAttachments, int translator, List<Status> statuses){
|
||||
super();
|
||||
|
@ -127,6 +129,9 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
this.targetedId = targetedId;
|
||||
this.translator = translator;
|
||||
pins = new ArrayList<>();
|
||||
if( context instanceof BaseMainActivity){
|
||||
bookmark = ((BaseMainActivity) context).getBookmark();
|
||||
}
|
||||
}
|
||||
|
||||
public StatusListAdapter(Context context, int position, String targetedId, boolean isOnWifi, int behaviorWithAttachments, int translator, List<Status> statuses){
|
||||
|
@ -141,6 +146,9 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
this.targetedId = targetedId;
|
||||
this.translator = translator;
|
||||
pins = new ArrayList<>();
|
||||
if( context instanceof BaseMainActivity){
|
||||
bookmark = ((BaseMainActivity) context).getBookmark();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -218,7 +226,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
LinearLayout status_replies;
|
||||
LinearLayout status_replies_profile_pictures;
|
||||
ProgressBar loader_replies;
|
||||
|
||||
Button fetch_more;
|
||||
ImageView new_element;
|
||||
|
||||
public View getView(){
|
||||
|
@ -228,6 +236,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
loader_replies = itemView.findViewById(R.id.loader_replies);
|
||||
fetch_more = itemView.findViewById(R.id.fetch_more);
|
||||
status_document_container = itemView.findViewById(R.id.status_document_container);
|
||||
status_content = itemView.findViewById(R.id.status_content);
|
||||
status_content_translated = itemView.findViewById(R.id.status_content_translated);
|
||||
|
@ -558,7 +567,11 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
|
||||
//-------- END -> Change the color in gray for accounts in DARK Theme only
|
||||
|
||||
|
||||
if( status.isFetchMore()) {
|
||||
holder.fetch_more.setVisibility(View.VISIBLE);
|
||||
holder.fetch_more.setEnabled(true);
|
||||
}else
|
||||
holder.fetch_more.setVisibility(View.GONE);
|
||||
|
||||
if( status.getReblog() == null)
|
||||
holder.status_favorite_count.setText(String.valueOf(status.getFavourites_count()));
|
||||
|
@ -1145,7 +1158,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
|
||||
|
||||
|
||||
private void loadAttachments(final Status status, ViewHolder holder){
|
||||
private void loadAttachments(final Status status, final ViewHolder holder){
|
||||
List<Attachment> attachments = status.getMedia_attachments();
|
||||
if( attachments != null && attachments.size() > 0){
|
||||
int i = 0;
|
||||
|
@ -1231,6 +1244,16 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
holder.status_document_container.setVisibility(View.GONE);
|
||||
}
|
||||
holder.status_show_more.setVisibility(View.GONE);
|
||||
|
||||
holder.fetch_more.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if(status.isFetchMore()) {
|
||||
status.setFetchMore(false);
|
||||
holder.fetch_more.setEnabled(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
@ -1388,4 +1411,5 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
public void onRetrieveSearchEmoji(List<Emojis> emojis) {
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -34,6 +34,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import fr.gouv.etalab.mastodon.R;
|
||||
import fr.gouv.etalab.mastodon.activities.BaseMainActivity;
|
||||
import fr.gouv.etalab.mastodon.activities.MainActivity;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveMissingFeedsAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
|
@ -68,10 +69,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
private String tag;
|
||||
private boolean swiped;
|
||||
private RecyclerView lv_status;
|
||||
private boolean isOnWifi;
|
||||
private int behaviorWithAttachments;
|
||||
private boolean showMediaOnly, showPinned;
|
||||
private int positionSpinnerTrans;
|
||||
private String lastReadStatus;
|
||||
private Intent streamingFederatedIntent, streamingLocalIntent;
|
||||
LinearLayoutManager mLayoutManager;
|
||||
|
@ -101,10 +99,10 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
|
||||
assert context != null;
|
||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
isOnWifi = Helper.isOnWIFI(context);
|
||||
positionSpinnerTrans = sharedpreferences.getInt(Helper.SET_TRANSLATOR, Helper.TRANS_YANDEX);
|
||||
boolean isOnWifi = Helper.isOnWIFI(context);
|
||||
int positionSpinnerTrans = sharedpreferences.getInt(Helper.SET_TRANSLATOR, Helper.TRANS_YANDEX);
|
||||
swipeRefreshLayout = rootView.findViewById(R.id.swipeContainer);
|
||||
behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS);
|
||||
int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
if( type == RetrieveFeedsAsyncTask.Type.HOME)
|
||||
lastReadStatus = sharedpreferences.getString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, null);
|
||||
|
@ -156,11 +154,11 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
swiped = true;
|
||||
MainActivity.countNewStatus = 0;
|
||||
if( type == RetrieveFeedsAsyncTask.Type.USER)
|
||||
asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, showMediaOnly, showPinned, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, null, showMediaOnly, showPinned, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
else if( type == RetrieveFeedsAsyncTask.Type.TAG)
|
||||
asyncTask = new RetrieveFeedsAsyncTask(context, type, tag, targetedId, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
asyncTask = new RetrieveFeedsAsyncTask(context, type, tag, targetedId, null, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
else
|
||||
asyncTask = new RetrieveFeedsAsyncTask(context, type, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
asyncTask = new RetrieveFeedsAsyncTask(context, type, null, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
});
|
||||
swipeRefreshLayout.setColorSchemeResources(R.color.mastodonC4,
|
||||
|
@ -253,20 +251,37 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
}
|
||||
|
||||
if( statuses != null && statuses.size() > 0) {
|
||||
if( type == RetrieveFeedsAsyncTask.Type.FAVOURITES ){
|
||||
this.statuses.addAll(statuses);
|
||||
}else {
|
||||
if (type == RetrieveFeedsAsyncTask.Type.HOME) {
|
||||
String bookmark = null;
|
||||
if( context instanceof BaseMainActivity){
|
||||
bookmark = ((BaseMainActivity) context).getBookmark();
|
||||
}
|
||||
int inc = 0;
|
||||
for (Status tmpStatus : statuses) {
|
||||
if (this.statuses.size() == 0 || Long.parseLong(tmpStatus.getId()) < Long.parseLong(this.statuses.get(this.statuses.size() - 1).getId())) {
|
||||
if (type == RetrieveFeedsAsyncTask.Type.HOME && firstLoad && lastReadStatus != null && Long.parseLong(tmpStatus.getId()) > Long.parseLong(lastReadStatus)) {
|
||||
if (bookmark != null){
|
||||
if (Long.parseLong(tmpStatus.getId()) > Long.parseLong(bookmark)) {
|
||||
tmpStatus.setNew(true);
|
||||
MainActivity.countNewStatus++;
|
||||
} else {
|
||||
tmpStatus.setNew(false);
|
||||
}
|
||||
}
|
||||
if( this.statuses != null && this.statuses.size() > 0) {
|
||||
for (Status status : this.statuses) {
|
||||
if (Long.parseLong(tmpStatus.getId()) == Long.parseLong(status.getId())) {
|
||||
break; //This toot was already added (security, should not happen)
|
||||
}else if (Long.parseLong(tmpStatus.getId()) < Long.parseLong(status.getId())) {
|
||||
this.statuses.add(tmpStatus);
|
||||
}
|
||||
if( inc == statuses.size() -1 && bookmark != null && Long.parseLong(statuses.get(inc).getId()) > Long.parseLong(bookmark) ){
|
||||
tmpStatus.setFetchMore(true);
|
||||
}
|
||||
}
|
||||
}else {
|
||||
this.statuses.add(tmpStatus);
|
||||
}
|
||||
inc++;
|
||||
}
|
||||
}else {
|
||||
this.statuses.addAll(statuses);
|
||||
}
|
||||
if( firstLoad && type == RetrieveFeedsAsyncTask.Type.HOME && statuses.size() > 0) {
|
||||
//Update the id of the last toot retrieved
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FFFFFFFF"
|
||||
android:pathData="M16.59,8.59L12,13.17 7.41,8.59 6,10l6,6 6,-6z"/>
|
||||
</vector>
|
|
@ -433,4 +433,20 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"/>
|
||||
</LinearLayout>
|
||||
<Button
|
||||
android:id="@+id/fetch_more"
|
||||
android:visibility="gone"
|
||||
android:textAllCaps="false"
|
||||
android:drawableLeft="@drawable/ic_expand_more"
|
||||
android:drawableStart="@drawable/ic_expand_more"
|
||||
android:gravity="center"
|
||||
android:layout_gravity="center"
|
||||
android:drawablePadding="5dp"
|
||||
android:textStyle="bold"
|
||||
android:textSize="16sp"
|
||||
android:maxLines="1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/Base.Widget.AppCompat.Button.Borderless"
|
||||
android:text="@string/fetch_more_toots" />
|
||||
</LinearLayout>
|
|
@ -411,4 +411,5 @@
|
|||
<string name="filter_regex">Filtrer avec une expression rationnelle</string>
|
||||
<string name="search">Rechercher</string>
|
||||
<string name="delete">Supprimer</string>
|
||||
<string name="fetch_more_toots">Afficher plus de pouets…</string>
|
||||
</resources>
|
||||
|
|
|
@ -369,7 +369,7 @@ Lütfen, almak istediğiniz itme bildirimlerini onaylayın.
|
|||
<string name="privacy_data">
|
||||
Hesaplardan yalnızca temel bilgiler cihazda saklanır.
|
||||
Bu veriler kesinlikle gizlidir ve yalnızca uygulama tarafından kullanılabilir.
|
||||
Uygulamanın silinmesi, bu verileri derhal kaldırır. \ N
|
||||
Uygulamanın silinmesi, bu verileri derhal kaldırır. \n
|
||||
⚠ Oturum açma ve parolalar asla saklanmaz. Yalnızca bir örneğe sahip güvenli bir kimlik doğrulama (SSL) sırasında kullanılırlar. </string>
|
||||
<string name="privacy_authorizations_title">Izinler:</string>
|
||||
<string name="privacy_authorizations">
|
||||
|
@ -395,7 +395,7 @@ Uygulama <b> izleme araçları kullanmaz </b>(kitle ölçümü, hata raporlama,
|
|||
- <b> Gson </b>: Taslaklar kaydetmek için </string>
|
||||
<string name="privacy_API_yandex_title">Modül tercümesi</string>
|
||||
<string name="privacy_API_yandex_authorizations">
|
||||
Uygulama cihazın yerel ayarını ve Yandex API\'sini kullanarak toots çevirme olanağı sunar. \ N
|
||||
Uygulama cihazın yerel ayarını ve Yandex API\'sini kullanarak toots çevirme olanağı sunar. \n
|
||||
Yandex\'in şu adreste bulunabilecek uygun gizlilik politikası vardır: https://yandex.ru/legal/confidential/?lang=en </string>
|
||||
<string name="thanks_text">
|
||||
Stephane\'a logo için teşekkür ederiz. </string>
|
||||
|
|
|
@ -447,4 +447,6 @@
|
|||
<string name="filter_regex">Filter out by regular expressions</string>
|
||||
<string name="search">Search</string>
|
||||
<string name="delete">Delete</string>
|
||||
|
||||
<string name="fetch_more_toots">Fetch more toots…</string>
|
||||
</resources>
|
Loading…
Reference in New Issue