diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/MainActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/MainActivity.java index a4fb0fb43..043d034d9 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/MainActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/MainActivity.java @@ -567,8 +567,8 @@ public class MainActivity extends AppCompatActivity .show(); }else if( id == R.id.action_size){ final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); - int textSize = sharedpreferences.getInt(Helper.SET_TEXT_SIZE,100); - int iconSize = sharedpreferences.getInt(Helper.SET_ICON_SIZE,100); + int textSize = sharedpreferences.getInt(Helper.SET_TEXT_SIZE,110); + int iconSize = sharedpreferences.getInt(Helper.SET_ICON_SIZE,130); AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setTitle(R.string.text_size); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveFeedsAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveFeedsAsyncTask.java index e8ee50c04..ec191247a 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveFeedsAsyncTask.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveFeedsAsyncTask.java @@ -15,14 +15,9 @@ package fr.gouv.etalab.mastodon.asynctasks; import android.content.Context; -import android.content.SharedPreferences; import android.os.AsyncTask; - -import java.util.List; - import fr.gouv.etalab.mastodon.client.API; import fr.gouv.etalab.mastodon.client.APIResponse; -import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveFeedsInterface; @@ -84,18 +79,6 @@ public class RetrieveFeedsAsyncTask extends AsyncTask { switch (action){ case HOME: apiResponse = api.getHomeTimeline(max_id); - final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); - boolean showPreview = sharedpreferences.getBoolean(Helper.SET_PREVIEW_REPLIES, false); - //Retrieves attached replies to a toot - if( showPreview){ - List statuses = apiResponse.getStatuses(); - if( statuses != null && statuses.size() > 0){ - for(fr.gouv.etalab.mastodon.client.Entities.Status status : statuses){ - fr.gouv.etalab.mastodon.client.Entities.Context statusContext = api.getStatusContext((status.getReblog() != null) ? status.getReblog().getId() : status.getId()); - status.setReplies(statusContext.getDescendants()); - } - } - } break; case LOCAL: apiResponse = api.getPublicTimeline(true, max_id); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveRepliesAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveRepliesAsyncTask.java new file mode 100644 index 000000000..ed6616494 --- /dev/null +++ b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveRepliesAsyncTask.java @@ -0,0 +1,65 @@ +/* Copyright 2017 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 . */ +package fr.gouv.etalab.mastodon.asynctasks; + +import android.content.Context; +import android.os.AsyncTask; + +import java.util.List; + +import fr.gouv.etalab.mastodon.client.API; +import fr.gouv.etalab.mastodon.client.APIResponse; +import fr.gouv.etalab.mastodon.interfaces.OnRetrieveRepliesInterface; + + +/** + * Created by Thomas on 18/08/2017. + * Retrieves replies to a toot + */ + +public class RetrieveRepliesAsyncTask extends AsyncTask { + + private Context context; + private APIResponse apiResponse; + private OnRetrieveRepliesInterface listener; + private List statuses; + + + + public RetrieveRepliesAsyncTask(Context context, List statuses, OnRetrieveRepliesInterface onRetrieveRepliesInterface){ + this.context = context; + this.statuses = statuses; + this.listener = onRetrieveRepliesInterface; + } + + @Override + protected Void doInBackground(Void... params) { + + API api = new API(context); + for (fr.gouv.etalab.mastodon.client.Entities.Status status : statuses) { + fr.gouv.etalab.mastodon.client.Entities.Context statusContext = api.getStatusContext((status.getReblog() != null) ? status.getReblog().getId() : status.getId()); + status.setReplies(statusContext.getDescendants()); + } + apiResponse = new APIResponse(); + apiResponse.setStatuses(statuses); + return null; + } + + @Override + protected void onPostExecute(Void result) { + listener.onRetrieveReplies(apiResponse); + } + +} diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/NotificationsListAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/NotificationsListAdapter.java index 848b36295..6fee6a2d6 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/NotificationsListAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/NotificationsListAdapter.java @@ -163,8 +163,8 @@ public class NotificationsListAdapter extends BaseAdapter implements OnPostActio final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); - int iconSizePercent = sharedpreferences.getInt(Helper.SET_ICON_SIZE, 100); - int textSizePercent = sharedpreferences.getInt(Helper.SET_TEXT_SIZE, 100); + int iconSizePercent = sharedpreferences.getInt(Helper.SET_ICON_SIZE, 130); + int textSizePercent = sharedpreferences.getInt(Helper.SET_TEXT_SIZE, 110); final float scale = context.getResources().getDisplayMetrics().density; 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 5ebbd5252..c1c2f7040 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 @@ -206,7 +206,7 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf //Display a preview for accounts that have replied *if enabled and only for home timeline* if( type == RetrieveFeedsAsyncTask.Type.HOME ) { - boolean showPreview = sharedpreferences.getBoolean(Helper.SET_PREVIEW_REPLIES, false); + boolean showPreview = sharedpreferences.getBoolean(Helper.SET_PREVIEW_REPLIES, true); if ( !showPreview || status.getReplies() == null || status.getReplies().size() == 0){ holder.status_replies.setVisibility(View.GONE); }else if(status.getReplies().size() > 0 ){ @@ -235,8 +235,8 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf holder.status_replies_text.setVisibility(View.VISIBLE); } } - int iconSizePercent = sharedpreferences.getInt(Helper.SET_ICON_SIZE, 100); - int textSizePercent = sharedpreferences.getInt(Helper.SET_TEXT_SIZE, 100); + int iconSizePercent = sharedpreferences.getInt(Helper.SET_ICON_SIZE, 130); + int textSizePercent = sharedpreferences.getInt(Helper.SET_TEXT_SIZE, 110); holder.status_more.getLayoutParams().height = (int) Helper.convertDpToPixel((20*iconSizePercent/100), context); holder.status_more.getLayoutParams().width = (int) Helper.convertDpToPixel((20*iconSizePercent/100), context); 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 73fdbd47f..d369077fa 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 @@ -32,10 +32,13 @@ import android.widget.RelativeLayout; import android.widget.Toast; import java.util.ArrayList; import java.util.List; + +import fr.gouv.etalab.mastodon.asynctasks.RetrieveRepliesAsyncTask; import fr.gouv.etalab.mastodon.client.APIResponse; import fr.gouv.etalab.mastodon.client.Entities.Account; import fr.gouv.etalab.mastodon.drawers.StatusListAdapter; import fr.gouv.etalab.mastodon.helper.Helper; +import fr.gouv.etalab.mastodon.interfaces.OnRetrieveRepliesInterface; import fr.gouv.etalab.mastodon.sqlite.AccountDAO; import fr.gouv.etalab.mastodon.sqlite.Sqlite; import mastodon.etalab.gouv.fr.mastodon.R; @@ -48,7 +51,7 @@ import fr.gouv.etalab.mastodon.interfaces.OnRetrieveFeedsInterface; * Created by Thomas on 24/04/2017. * Fragment to display content related to status */ -public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsInterface { +public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsInterface, OnRetrieveRepliesInterface { private boolean flag_loading; @@ -307,10 +310,37 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn } firstLoad = false; + //Retrieves replies + if(statuses != null && statuses.size() > 0 && type == RetrieveFeedsAsyncTask.Type.HOME ) { + final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + boolean showPreview = sharedpreferences.getBoolean(Helper.SET_PREVIEW_REPLIES, true); + //Retrieves attached replies to a toot + if (showPreview) { + new RetrieveRepliesAsyncTask(context, statuses, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } + } + } public void scrollToTop(){ if( lv_status != null) lv_status.setAdapter(statusListAdapter); } + + @Override + public void onRetrieveReplies(APIResponse apiResponse) { + + if( apiResponse.getError() != null || apiResponse.getStatuses() == null || apiResponse.getStatuses().size() == 0){ + return; + } + List modifiedStatus = apiResponse.getStatuses(); + for(Status stmp: modifiedStatus){ + for(Status status: statuses){ + if( status.getId().equals(stmp.getId())) + statuses.set(0,stmp); + } + } + statusListAdapter.notifyDataSetChanged(); + + } } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsFragment.java index fc06e98b5..2ad1dcf54 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsFragment.java @@ -120,7 +120,7 @@ public class SettingsFragment extends Fragment { } }); - boolean preview_reply = sharedpreferences.getBoolean(Helper.SET_PREVIEW_REPLIES, false); + boolean preview_reply = sharedpreferences.getBoolean(Helper.SET_PREVIEW_REPLIES, true); final CheckBox set_preview_reply = (CheckBox) rootView.findViewById(R.id.set_preview_reply); set_preview_reply.setChecked(preview_reply); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/interfaces/OnRetrieveRepliesInterface.java b/app/src/main/java/fr/gouv/etalab/mastodon/interfaces/OnRetrieveRepliesInterface.java new file mode 100644 index 000000000..de41322fd --- /dev/null +++ b/app/src/main/java/fr/gouv/etalab/mastodon/interfaces/OnRetrieveRepliesInterface.java @@ -0,0 +1,25 @@ +/* Copyright 2017 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 . */ +package fr.gouv.etalab.mastodon.interfaces; + +import fr.gouv.etalab.mastodon.client.APIResponse; + +/** + * Created by Thomas on 28/08/2017. + * Interface when replies have been retrieved + */ +public interface OnRetrieveRepliesInterface { + void onRetrieveReplies(APIResponse apiResponse); +}