From a36b57feb7c135369dd219f62f05b7d9738f9fb1 Mon Sep 17 00:00:00 2001 From: stom79 Date: Sun, 16 Dec 2018 14:29:23 +0100 Subject: [PATCH] Some fixes --- .../mastodon/activities/HashTagActivity.java | 2 +- .../mastodon/activities/ListActivity.java | 7 +++--- .../activities/OwnerStatusActivity.java | 4 +--- .../mastodon/activities/PeertubeActivity.java | 4 +--- .../activities/ShowAccountActivity.java | 5 +--- .../activities/ShowConversationActivity.java | 4 +--- .../mastodon/activities/TootActivity.java | 3 +-- .../mastodon/drawers/StatusListAdapter.java | 23 +++++++------------ .../fragments/DisplayBookmarksFragment.java | 6 ++--- .../fragments/DisplayStatusFragment.java | 6 ++--- .../gouv/etalab/mastodon/helper/Helper.java | 11 ++------- 11 files changed, 23 insertions(+), 52 deletions(-) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/HashTagActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/HashTagActivity.java index 6666c7810..77f11c9f3 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/HashTagActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/HashTagActivity.java @@ -126,7 +126,7 @@ public class HashTagActivity extends BaseActivity implements OnRetrieveFeedsInte mainLoader.setVisibility(View.VISIBLE); nextElementLoader.setVisibility(View.GONE); int positionSpinnerTrans = (sharedpreferences.getInt(Helper.SET_TRANSLATOR, Helper.TRANS_YANDEX)); - statusListAdapter = new StatusListAdapter(HashTagActivity.this, RetrieveFeedsAsyncTask.Type.TAG, null, isOnWifi, behaviorWithAttachments, positionSpinnerTrans, this.statuses); + statusListAdapter = new StatusListAdapter(HashTagActivity.this, RetrieveFeedsAsyncTask.Type.TAG, null, isOnWifi, this.statuses); lv_status.setAdapter(statusListAdapter); setTitle(String.format("#%s", tag)); swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/ListActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/ListActivity.java index 2338457a7..768b42575 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/ListActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/ListActivity.java @@ -21,6 +21,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.os.AsyncTask; import android.os.Bundle; +import android.support.annotation.NonNull; import android.support.v4.content.ContextCompat; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.app.AlertDialog; @@ -116,10 +117,8 @@ public class ListActivity extends BaseActivity implements OnListActionInterface mainLoader.setVisibility(View.VISIBLE); nextElementLoader.setVisibility(View.GONE); boolean isOnWifi = Helper.isOnWIFI(ListActivity.this); - int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS); - int positionSpinnerTrans = sharedpreferences.getInt(Helper.SET_TRANSLATOR, Helper.TRANS_YANDEX); - statusListAdapter = new StatusListAdapter(ListActivity.this, RetrieveFeedsAsyncTask.Type.LIST, null, isOnWifi, behaviorWithAttachments, positionSpinnerTrans, this.statuses); + statusListAdapter = new StatusListAdapter(ListActivity.this, RetrieveFeedsAsyncTask.Type.LIST, null, isOnWifi, this.statuses); lv_status.setAdapter(statusListAdapter); mLayoutManager = new LinearLayoutManager(ListActivity.this); @@ -139,7 +138,7 @@ public class ListActivity extends BaseActivity implements OnListActionInterface lv_status.addOnScrollListener(new RecyclerView.OnScrollListener() { - public void onScrolled(RecyclerView recyclerView, int dx, int dy) + public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition(); if(dy > 0){ diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/OwnerStatusActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/OwnerStatusActivity.java index 3852bb586..d3531bd6c 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/OwnerStatusActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/OwnerStatusActivity.java @@ -164,11 +164,9 @@ public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeeds firstLoad = true; swiped = false; boolean isOnWifi = Helper.isOnWIFI(OwnerStatusActivity.this); - int positionSpinnerTrans = sharedpreferences.getInt(Helper.SET_TRANSLATOR, Helper.TRANS_YANDEX); - int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS); lv_status.addItemDecoration(new DividerItemDecoration(OwnerStatusActivity.this, DividerItemDecoration.VERTICAL)); String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); - statusListAdapter = new StatusListAdapter(OwnerStatusActivity.this, RetrieveFeedsAsyncTask.Type.CACHE_STATUS, userId, isOnWifi, behaviorWithAttachments, positionSpinnerTrans, this.statuses); + statusListAdapter = new StatusListAdapter(OwnerStatusActivity.this, RetrieveFeedsAsyncTask.Type.CACHE_STATUS, userId, isOnWifi, this.statuses); lv_status.setAdapter(statusListAdapter); mLayoutManager = new LinearLayoutManager(OwnerStatusActivity.this); lv_status.setLayoutManager(mLayoutManager); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeActivity.java index acd05cb07..3d87481b1 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeActivity.java @@ -398,10 +398,8 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube }else { SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); boolean isOnWifi = Helper.isOnWIFI(PeertubeActivity.this); - int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS); - int positionSpinnerTrans = sharedpreferences.getInt(Helper.SET_TRANSLATOR, Helper.TRANS_YANDEX); String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); - StatusListAdapter statusListAdapter = new StatusListAdapter(PeertubeActivity.this, RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE, userId, isOnWifi, behaviorWithAttachments, positionSpinnerTrans, statuses); + StatusListAdapter statusListAdapter = new StatusListAdapter(PeertubeActivity.this, RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE, userId, isOnWifi, statuses); RecyclerView lv_comments = findViewById(R.id.peertube_comments); LinearLayoutManager mLayoutManager = new LinearLayoutManager(PeertubeActivity.this); lv_comments.setLayoutManager(mLayoutManager); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowAccountActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowAccountActivity.java index 6db644a18..dad8440db 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowAccountActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowAccountActivity.java @@ -199,10 +199,7 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt statuses = new ArrayList<>(); boolean isOnWifi = Helper.isOnWIFI(getApplicationContext()); - int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS); - int positionSpinnerTrans = sharedpreferences.getInt(Helper.SET_TRANSLATOR, Helper.TRANS_YANDEX); - - statusListAdapter = new StatusListAdapter(getApplicationContext(), RetrieveFeedsAsyncTask.Type.USER, accountId, isOnWifi, behaviorWithAttachments, positionSpinnerTrans, this.statuses); + statusListAdapter = new StatusListAdapter(getApplicationContext(), RetrieveFeedsAsyncTask.Type.USER, accountId, isOnWifi, this.statuses); showMediaOnly = false; showPinned = false; diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowConversationActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowConversationActivity.java index 2e55059f3..7a53acc67 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowConversationActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowConversationActivity.java @@ -198,13 +198,11 @@ public class ShowConversationActivity extends BaseActivity implements OnRetriev swipeRefreshLayout = findViewById(R.id.swipeContainer); boolean isOnWifi = Helper.isOnWIFI(getApplicationContext()); - int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS); - int positionSpinnerTrans = sharedpreferences.getInt(Helper.SET_TRANSLATOR, Helper.TRANS_YANDEX); if( initialStatus != null) statuses.add(initialStatus); else statuses.add(detailsStatus); - statusListAdapter = new StatusListAdapter(ShowConversationActivity.this, 0, null, isOnWifi, behaviorWithAttachments, positionSpinnerTrans, statuses); + statusListAdapter = new StatusListAdapter(ShowConversationActivity.this, 0, null, isOnWifi, statuses); final LinearLayoutManager mLayoutManager; mLayoutManager = new LinearLayoutManager(this); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java index 81eb4170a..84dfd5183 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java @@ -118,7 +118,6 @@ import fr.gouv.etalab.mastodon.client.Entities.Results; import fr.gouv.etalab.mastodon.client.Entities.Status; import fr.gouv.etalab.mastodon.client.Entities.StoredStatus; import fr.gouv.etalab.mastodon.client.Entities.Version; -import fr.gouv.etalab.mastodon.client.Glide.GlideApp; import fr.gouv.etalab.mastodon.client.HttpsConnection; import fr.gouv.etalab.mastodon.drawers.AccountsReplyAdapter; import fr.gouv.etalab.mastodon.drawers.AccountsSearchAdapter; @@ -1477,7 +1476,7 @@ public class TootActivity extends BaseActivity implements OnRetrieveSearcAccount final EditText input = popup_media_description.findViewById(R.id.media_description); input.setFilters(new InputFilter[]{new InputFilter.LengthFilter(420)}); final ImageView media_picture = popup_media_description.findViewById(R.id.media_picture); - GlideApp.with(getApplicationContext()) + Glide.with(getApplicationContext()) .asBitmap() .load(attachment.getUrl()) .into(new SimpleTarget() { diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java index ef84b573d..f86d50f2e 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java @@ -140,61 +140,53 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct private List statuses; private LayoutInflater layoutInflater; private boolean isOnWifi; - private int translator; - private int behaviorWithAttachments; private StatusListAdapter statusListAdapter; private RetrieveFeedsAsyncTask.Type type; private String targetedId; private final int HIDDEN_STATUS = 0; - public static final int DISPLAYED_STATUS = 1; - public static final int FOCUSED_STATUS = 2; - public static final int COMPACT_STATUS = 3; + private static final int DISPLAYED_STATUS = 1; + static final int FOCUSED_STATUS = 2; + private static final int COMPACT_STATUS = 3; private int conversationPosition; private List timedMute; private boolean redraft; private Status toot; private TagTimeline tagTimeline; - public StatusListAdapter(Context context, RetrieveFeedsAsyncTask.Type type, String targetedId, boolean isOnWifi, int behaviorWithAttachments, int translator, List statuses){ + public StatusListAdapter(Context context, RetrieveFeedsAsyncTask.Type type, String targetedId, boolean isOnWifi, List statuses){ super(); this.context = context; this.statuses = statuses; this.isOnWifi = isOnWifi; - this.behaviorWithAttachments = behaviorWithAttachments; layoutInflater = LayoutInflater.from(this.context); statusListAdapter = this; this.type = type; this.targetedId = targetedId; - this.translator = translator; redraft = false; } - public StatusListAdapter(Context context, TagTimeline tagTimeline, String targetedId, boolean isOnWifi, int behaviorWithAttachments, int translator, List statuses){ + public StatusListAdapter(Context context, TagTimeline tagTimeline, String targetedId, boolean isOnWifi, List statuses){ super(); this.context = context; this.statuses = statuses; this.isOnWifi = isOnWifi; - this.behaviorWithAttachments = behaviorWithAttachments; layoutInflater = LayoutInflater.from(this.context); statusListAdapter = this; this.type = RetrieveFeedsAsyncTask.Type.TAG; this.targetedId = targetedId; - this.translator = translator; redraft = false; this.tagTimeline = tagTimeline; } - public StatusListAdapter(Context context, int position, String targetedId, boolean isOnWifi, int behaviorWithAttachments, int translator, List statuses){ + public StatusListAdapter(Context context, int position, String targetedId, boolean isOnWifi, List statuses){ this.context = context; this.statuses = statuses; this.isOnWifi = isOnWifi; - this.behaviorWithAttachments = behaviorWithAttachments; layoutInflater = LayoutInflater.from(this.context); statusListAdapter = this; this.type = RetrieveFeedsAsyncTask.Type.CONTEXT; this.conversationPosition = position; this.targetedId = targetedId; - this.translator = translator; redraft = false; } @@ -542,7 +534,8 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct boolean share_details = sharedpreferences.getBoolean(Helper.SET_SHARE_DETAILS, true); boolean confirmFav = sharedpreferences.getBoolean(Helper.SET_NOTIF_VALIDATION_FAV, false); boolean confirmBoost = sharedpreferences.getBoolean(Helper.SET_NOTIF_VALIDATION, true); - + int translator = sharedpreferences.getInt(Helper.SET_TRANSLATOR, Helper.TRANS_YANDEX); + int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS); if( type != RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE && !isCompactMode && displayBookmarkButton) holder.status_bookmark.setVisibility(View.VISIBLE); else diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayBookmarksFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayBookmarksFragment.java index d66f670e9..eecc5d0d1 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayBookmarksFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayBookmarksFragment.java @@ -102,12 +102,10 @@ public class DisplayBookmarksFragment extends Fragment implements OnRetrieveFeed }catch (Exception ignored){} final boolean isOnWifi = Helper.isOnWIFI(context); final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); - final int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS); - final int positionSpinnerTrans = sharedpreferences.getInt(Helper.SET_TRANSLATOR, Helper.TRANS_YANDEX); statuses = apiResponse.getStatuses(); if( statuses != null && statuses.size() > 0) { LinearLayoutManager mLayoutManager = new LinearLayoutManager(context); - statusListAdapter = new StatusListAdapter(context, RetrieveFeedsAsyncTask.Type.CACHE_BOOKMARKS, null, isOnWifi, behaviorWithAttachments, positionSpinnerTrans, this.statuses); + statusListAdapter = new StatusListAdapter(context, RetrieveFeedsAsyncTask.Type.CACHE_BOOKMARKS, null, isOnWifi, this.statuses); lv_status.setAdapter(statusListAdapter); lv_status.setLayoutManager(mLayoutManager); }else { @@ -138,7 +136,7 @@ public class DisplayBookmarksFragment extends Fragment implements OnRetrieveFeed new StatusCacheDAO(context, db).removeAllStatus(StatusCacheDAO.STATUS_CACHE); statuses = new ArrayList<>(); statuses.clear(); - statusListAdapter = new StatusListAdapter(context, RetrieveFeedsAsyncTask.Type.CACHE_BOOKMARKS, null, isOnWifi, behaviorWithAttachments, positionSpinnerTrans, statuses); + statusListAdapter = new StatusListAdapter(context, RetrieveFeedsAsyncTask.Type.CACHE_BOOKMARKS, null, isOnWifi, statuses); lv_status.setAdapter(statusListAdapter); statusListAdapter.notifyDataSetChanged(); textviewNoAction.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java index 2cbfd9f27..c5521e7dc 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java @@ -146,9 +146,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn assert context != null; sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); boolean isOnWifi = Helper.isOnWIFI(context); - int positionSpinnerTrans = sharedpreferences.getInt(Helper.SET_TRANSLATOR, Helper.TRANS_YANDEX); swipeRefreshLayout = rootView.findViewById(R.id.swipeContainer); - int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS); lv_status = rootView.findViewById(R.id.lv_status); mainLoader = rootView.findViewById(R.id.loader); nextElementLoader = rootView.findViewById(R.id.loading_next_status); @@ -165,12 +163,12 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn List tagTimelines = new SearchDAO(context, db).getTimelineInfo(tag); if( tagTimelines != null && tagTimelines.size() > 0) { tagTimeline = tagTimelines.get(0); - statusListAdapter = new StatusListAdapter(context, tagTimeline, targetedId, isOnWifi, behaviorWithAttachments, positionSpinnerTrans, this.statuses); + statusListAdapter = new StatusListAdapter(context, tagTimeline, targetedId, isOnWifi, this.statuses); lv_status.setAdapter(statusListAdapter); } }else if( search_peertube == null && (instanceType == null || instanceType.equals("MASTODON"))) { BaseMainActivity.displayPeertube = null; - statusListAdapter = new StatusListAdapter(context, type, targetedId, isOnWifi, behaviorWithAttachments, positionSpinnerTrans, this.statuses); + statusListAdapter = new StatusListAdapter(context, type, targetedId, isOnWifi, this.statuses); lv_status.setAdapter(statusListAdapter); }else { BaseMainActivity.displayPeertube = remoteInstance; diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java index 9ac9101d5..504742f10 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java @@ -341,6 +341,7 @@ public class Helper { public static final String SET_AUTOMATICALLY_SPLIT_TOOTS_SIZE = "set_automatically_split_toots_size"; public static final String SET_TRUNCATE_TOOTS_SIZE = "set_truncate_toots_size"; public static final String SET_ART_WITH_NSFW = "set_art_with_nsfw"; + //End points public static final String EP_AUTHORIZE = "/oauth/authorize"; @@ -1050,15 +1051,7 @@ public class Helper { */ public static String getLiveInstance(Context context){ final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); - SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); - String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); - if( userId == null) //User not authenticated - return null; - Account account = new AccountDAO(context, db).getAccountByID(userId); - if( account != null){ - return account.getInstance().trim(); - } //User not in db - return null; + return sharedpreferences.getString(Helper.PREF_INSTANCE, null); } public static String getLiveInstanceWithProtocol(Context context) {