Try to accelerate the process
This commit is contained in:
parent
b4c08a3225
commit
49c5acdd47
|
@ -0,0 +1,171 @@
|
|||
/* Copyright 2018 Thomas Schneider
|
||||
*
|
||||
* This file is a part of Mastalab
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* Mastalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with Mastalab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
package fr.gouv.etalab.mastodon.client.Entities;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
|
||||
/**
|
||||
* Created by Thomas on 29/11/2018.
|
||||
* Manage preferences
|
||||
*/
|
||||
public class Preferences {
|
||||
|
||||
private String userId;
|
||||
private boolean displayBookmarkButton, fullAttachement, isCompactMode, trans_forced, expand_cw, expand_media, display_card, display_video_preview, share_details;
|
||||
private int iconSizePercent, textSizePercent, theme, truncate_toots_size, timeout;
|
||||
|
||||
|
||||
public Preferences(Context context){
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
displayBookmarkButton = sharedpreferences.getBoolean(Helper.SET_SHOW_BOOKMARK, false);
|
||||
fullAttachement = sharedpreferences.getBoolean(Helper.SET_FULL_PREVIEW, false);
|
||||
isCompactMode = sharedpreferences.getBoolean(Helper.SET_COMPACT_MODE, false);
|
||||
iconSizePercent = sharedpreferences.getInt(Helper.SET_ICON_SIZE, 130);
|
||||
textSizePercent = sharedpreferences.getInt(Helper.SET_TEXT_SIZE, 110);
|
||||
trans_forced = sharedpreferences.getBoolean(Helper.SET_TRANS_FORCED, false);
|
||||
theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
||||
expand_cw = sharedpreferences.getBoolean(Helper.SET_EXPAND_CW, false);
|
||||
expand_media = sharedpreferences.getBoolean(Helper.SET_EXPAND_MEDIA, false);
|
||||
display_card = sharedpreferences.getBoolean(Helper.SET_DISPLAY_CARD, false);
|
||||
display_video_preview = sharedpreferences.getBoolean(Helper.SET_DISPLAY_VIDEO_PREVIEWS, true);
|
||||
truncate_toots_size = sharedpreferences.getInt(Helper.SET_TRUNCATE_TOOTS_SIZE, 0);
|
||||
timeout = sharedpreferences.getInt(Helper.SET_NSFW_TIMEOUT, 5);
|
||||
share_details = sharedpreferences.getBoolean(Helper.SET_SHARE_DETAILS, true);
|
||||
}
|
||||
|
||||
public String getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(String userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public boolean isDisplayBookmarkButton() {
|
||||
return displayBookmarkButton;
|
||||
}
|
||||
|
||||
public void setDisplayBookmarkButton(boolean displayBookmarkButton) {
|
||||
this.displayBookmarkButton = displayBookmarkButton;
|
||||
}
|
||||
|
||||
public boolean isFullAttachement() {
|
||||
return fullAttachement;
|
||||
}
|
||||
|
||||
public void setFullAttachement(boolean fullAttachement) {
|
||||
this.fullAttachement = fullAttachement;
|
||||
}
|
||||
|
||||
public boolean isCompactMode() {
|
||||
return isCompactMode;
|
||||
}
|
||||
|
||||
public void setCompactMode(boolean compactMode) {
|
||||
isCompactMode = compactMode;
|
||||
}
|
||||
|
||||
public boolean isTrans_forced() {
|
||||
return trans_forced;
|
||||
}
|
||||
|
||||
public void setTrans_forced(boolean trans_forced) {
|
||||
this.trans_forced = trans_forced;
|
||||
}
|
||||
|
||||
public boolean isExpand_cw() {
|
||||
return expand_cw;
|
||||
}
|
||||
|
||||
public void setExpand_cw(boolean expand_cw) {
|
||||
this.expand_cw = expand_cw;
|
||||
}
|
||||
|
||||
public boolean isExpand_media() {
|
||||
return expand_media;
|
||||
}
|
||||
|
||||
public void setExpand_media(boolean expand_media) {
|
||||
this.expand_media = expand_media;
|
||||
}
|
||||
|
||||
public boolean isDisplay_card() {
|
||||
return display_card;
|
||||
}
|
||||
|
||||
public void setDisplay_card(boolean display_card) {
|
||||
this.display_card = display_card;
|
||||
}
|
||||
|
||||
public boolean isDisplay_video_preview() {
|
||||
return display_video_preview;
|
||||
}
|
||||
|
||||
public void setDisplay_video_preview(boolean display_video_preview) {
|
||||
this.display_video_preview = display_video_preview;
|
||||
}
|
||||
|
||||
public boolean isShare_details() {
|
||||
return share_details;
|
||||
}
|
||||
|
||||
public void setShare_details(boolean share_details) {
|
||||
this.share_details = share_details;
|
||||
}
|
||||
|
||||
public int getIconSizePercent() {
|
||||
return iconSizePercent;
|
||||
}
|
||||
|
||||
public void setIconSizePercent(int iconSizePercent) {
|
||||
this.iconSizePercent = iconSizePercent;
|
||||
}
|
||||
|
||||
public int getTextSizePercent() {
|
||||
return textSizePercent;
|
||||
}
|
||||
|
||||
public void setTextSizePercent(int textSizePercent) {
|
||||
this.textSizePercent = textSizePercent;
|
||||
}
|
||||
|
||||
public int getTheme() {
|
||||
return theme;
|
||||
}
|
||||
|
||||
public void setTheme(int theme) {
|
||||
this.theme = theme;
|
||||
}
|
||||
|
||||
public int getTruncate_toots_size() {
|
||||
return truncate_toots_size;
|
||||
}
|
||||
|
||||
public void setTruncate_toots_size(int truncate_toots_size) {
|
||||
this.truncate_toots_size = truncate_toots_size;
|
||||
}
|
||||
|
||||
public int getTimeout() {
|
||||
return timeout;
|
||||
}
|
||||
|
||||
public void setTimeout(int timeout) {
|
||||
this.timeout = timeout;
|
||||
}
|
||||
}
|
|
@ -103,6 +103,7 @@ import fr.gouv.etalab.mastodon.client.Entities.Attachment;
|
|||
import fr.gouv.etalab.mastodon.client.Entities.Card;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Emojis;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Error;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Preferences;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Status;
|
||||
import fr.gouv.etalab.mastodon.fragments.DisplayStatusFragment;
|
||||
import fr.gouv.etalab.mastodon.helper.CrossActions;
|
||||
|
@ -150,9 +151,9 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
private List<String> timedMute;
|
||||
private boolean redraft;
|
||||
private Status toot;
|
||||
private Preferences preferences;
|
||||
|
||||
|
||||
public StatusListAdapter(Context context, RetrieveFeedsAsyncTask.Type type, String targetedId, boolean isOnWifi, int behaviorWithAttachments, int translator, List<Status> statuses){
|
||||
public StatusListAdapter(Context context, Preferences preferences, RetrieveFeedsAsyncTask.Type type, String targetedId, boolean isOnWifi, int behaviorWithAttachments, int translator, List<Status> statuses){
|
||||
super();
|
||||
this.context = context;
|
||||
this.statuses = statuses;
|
||||
|
@ -164,9 +165,10 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
this.targetedId = targetedId;
|
||||
this.translator = translator;
|
||||
redraft = false;
|
||||
this.preferences = preferences;
|
||||
}
|
||||
|
||||
public StatusListAdapter(Context context, int position, String targetedId, boolean isOnWifi, int behaviorWithAttachments, int translator, List<Status> statuses){
|
||||
public StatusListAdapter(Context context, Preferences preferences, int position, String targetedId, boolean isOnWifi, int behaviorWithAttachments, int translator, List<Status> statuses){
|
||||
this.context = context;
|
||||
this.statuses = statuses;
|
||||
this.isOnWifi = isOnWifi;
|
||||
|
@ -178,6 +180,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
this.targetedId = targetedId;
|
||||
this.translator = translator;
|
||||
redraft = false;
|
||||
this.preferences = preferences;
|
||||
}
|
||||
|
||||
public void updateMuted(List<String> timedMute){
|
||||
|
@ -429,10 +432,21 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
|
||||
status.setItemViewType(viewHolder.getItemViewType());
|
||||
|
||||
final String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
boolean displayBookmarkButton = sharedpreferences.getBoolean(Helper.SET_SHOW_BOOKMARK, false);
|
||||
boolean fullAttachement = sharedpreferences.getBoolean(Helper.SET_FULL_PREVIEW, false);
|
||||
final String userId = preferences.getUserId();
|
||||
boolean displayBookmarkButton = preferences.isDisplayBookmarkButton();
|
||||
boolean fullAttachement = preferences.isFullAttachement();
|
||||
boolean isCompactMode = sharedpreferences.getBoolean(Helper.SET_COMPACT_MODE, false);
|
||||
int iconSizePercent = sharedpreferences.getInt(Helper.SET_ICON_SIZE, 130);
|
||||
int textSizePercent = sharedpreferences.getInt(Helper.SET_TEXT_SIZE, 110);
|
||||
final boolean trans_forced = sharedpreferences.getBoolean(Helper.SET_TRANS_FORCED, false);
|
||||
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
||||
boolean expand_cw = sharedpreferences.getBoolean(Helper.SET_EXPAND_CW, false);
|
||||
boolean expand_media = sharedpreferences.getBoolean(Helper.SET_EXPAND_MEDIA, false);
|
||||
boolean display_card = sharedpreferences.getBoolean(Helper.SET_DISPLAY_CARD, false);
|
||||
boolean display_video_preview = sharedpreferences.getBoolean(Helper.SET_DISPLAY_VIDEO_PREVIEWS, true);
|
||||
int truncate_toots_size = sharedpreferences.getInt(Helper.SET_TRUNCATE_TOOTS_SIZE, 0);
|
||||
final int timeout = sharedpreferences.getInt(Helper.SET_NSFW_TIMEOUT, 5);
|
||||
boolean share_details = sharedpreferences.getBoolean(Helper.SET_SHARE_DETAILS, true);
|
||||
|
||||
if( type != RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE && !isCompactMode && displayBookmarkButton)
|
||||
holder.status_bookmark.setVisibility(View.VISIBLE);
|
||||
|
@ -454,9 +468,8 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
holder.new_element.setVisibility(View.VISIBLE);
|
||||
else
|
||||
holder.new_element.setVisibility(View.GONE);
|
||||
int iconSizePercent = sharedpreferences.getInt(Helper.SET_ICON_SIZE, 130);
|
||||
int textSizePercent = sharedpreferences.getInt(Helper.SET_TEXT_SIZE, 110);
|
||||
final boolean trans_forced = sharedpreferences.getBoolean(Helper.SET_TRANS_FORCED, false);
|
||||
|
||||
|
||||
holder.status_more.getLayoutParams().height = (int) Helper.convertDpToPixel((20*iconSizePercent/100), context);
|
||||
holder.status_more.getLayoutParams().width = (int) Helper.convertDpToPixel((20*iconSizePercent/100), context);
|
||||
holder.status_privacy.getLayoutParams().height = (int) Helper.convertDpToPixel((20*iconSizePercent/100), context);
|
||||
|
@ -508,7 +521,8 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
}
|
||||
|
||||
//Manages theme for icon colors
|
||||
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
||||
|
||||
|
||||
if( theme == Helper.THEME_BLACK)
|
||||
changeDrawableColor(context, R.drawable.ic_fiber_new,R.color.dark_icon);
|
||||
else
|
||||
|
@ -519,8 +533,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
else
|
||||
holder.status_privacy.setVisibility(View.VISIBLE);
|
||||
|
||||
boolean expand_cw = sharedpreferences.getBoolean(Helper.SET_EXPAND_CW, false);
|
||||
boolean expand_media = sharedpreferences.getBoolean(Helper.SET_EXPAND_MEDIA, false);
|
||||
|
||||
|
||||
changeDrawableColor(context, R.drawable.video_preview,R.color.white);
|
||||
if( theme == Helper.THEME_BLACK){
|
||||
|
@ -717,7 +730,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
});
|
||||
}
|
||||
holder.status_content.setText(status.getContentSpan(), TextView.BufferType.SPANNABLE);
|
||||
int truncate_toots_size = sharedpreferences.getInt(Helper.SET_TRUNCATE_TOOTS_SIZE, 0);
|
||||
|
||||
if( truncate_toots_size > 0) {
|
||||
holder.status_content.setMaxLines(truncate_toots_size);
|
||||
if (status.getNumberLines() == -1) {
|
||||
|
@ -811,7 +824,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
//-------- END -> Manages translations
|
||||
|
||||
if( status.getAccount() == null) {
|
||||
Account account = new AccountDAO(context, db).getAccountByID(sharedpreferences.getString(Helper.PREF_KEY_ID, null));
|
||||
Account account = new AccountDAO(context, db).getAccountByID(userId);
|
||||
status.setAccount(account);
|
||||
}
|
||||
//Displays name & emoji in toot header
|
||||
|
@ -1260,7 +1273,6 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
holder.status_pin.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
boolean display_card = sharedpreferences.getBoolean(Helper.SET_DISPLAY_CARD, false);
|
||||
|
||||
if( status.getWebviewURL() != null){
|
||||
holder.status_cardview_webview.loadUrl(status.getWebviewURL());
|
||||
|
@ -1272,7 +1284,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
holder.status_cardview_video.setVisibility(View.GONE);
|
||||
holder.webview_preview.setVisibility(View.VISIBLE);
|
||||
}
|
||||
boolean display_video_preview = sharedpreferences.getBoolean(Helper.SET_DISPLAY_VIDEO_PREVIEWS, true);
|
||||
|
||||
if( (type == RetrieveFeedsAsyncTask.Type.CONTEXT && position == conversationPosition ) || display_card || display_video_preview){
|
||||
|
||||
if( type == RetrieveFeedsAsyncTask.Type.CONTEXT & position == conversationPosition)
|
||||
|
@ -1429,7 +1441,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
if they want. Images are then hidden again.
|
||||
-> Default value is set to 5 seconds
|
||||
*/
|
||||
final int timeout = sharedpreferences.getInt(Helper.SET_NSFW_TIMEOUT, 5);
|
||||
|
||||
if (timeout > 0) {
|
||||
new CountDownTimer((timeout * 1000), 1000) {
|
||||
public void onTick(long millisUntilFinished) {
|
||||
|
@ -1651,7 +1663,6 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
String targeted_id = status.getAccount().getId();
|
||||
Date date_mute = new Date(time);
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
Account account = new AccountDAO(context, db).getAccountByID(userId);
|
||||
new TempMuteDAO(context, db).insert(account, targeted_id, new Date(time));
|
||||
if( timedMute != null && !timedMute.contains(account.getId()))
|
||||
|
@ -1717,7 +1728,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
url = status.getUrl();
|
||||
}
|
||||
String extra_text;
|
||||
boolean share_details = sharedpreferences.getBoolean(Helper.SET_SHARE_DETAILS, true);
|
||||
|
||||
if( share_details) {
|
||||
extra_text = (status.getReblog() != null) ? status.getReblog().getAccount().getAcct() : status.getAccount().getAcct();
|
||||
if (extra_text.split("@").length == 1)
|
||||
|
|
Loading…
Reference in New Issue