Improves replies mechanism with an asynchronous call once toots are loaded.
This commit is contained in:
parent
53175e187c
commit
40f35369ca
|
@ -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);
|
||||
|
|
|
@ -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<Void, Void, Void> {
|
|||
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<fr.gouv.etalab.mastodon.client.Entities.Status> 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);
|
||||
|
|
|
@ -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 <http://www.gnu.org/licenses>. */
|
||||
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<Void, Void, Void> {
|
||||
|
||||
private Context context;
|
||||
private APIResponse apiResponse;
|
||||
private OnRetrieveRepliesInterface listener;
|
||||
private List<fr.gouv.etalab.mastodon.client.Entities.Status> statuses;
|
||||
|
||||
|
||||
|
||||
public RetrieveRepliesAsyncTask(Context context, List<fr.gouv.etalab.mastodon.client.Entities.Status> 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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<Status> modifiedStatus = apiResponse.getStatuses();
|
||||
for(Status stmp: modifiedStatus){
|
||||
for(Status status: statuses){
|
||||
if( status.getId().equals(stmp.getId()))
|
||||
statuses.set(0,stmp);
|
||||
}
|
||||
}
|
||||
statusListAdapter.notifyDataSetChanged();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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 <http://www.gnu.org/licenses>. */
|
||||
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);
|
||||
}
|
Loading…
Reference in New Issue