Fix boost/fav not updated.
This commit is contained in:
parent
0cf5920956
commit
dc6c595186
|
@ -58,6 +58,7 @@ import android.text.Editable;
|
|||
import android.text.InputFilter;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Patterns;
|
||||
import android.util.SparseArray;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
|
@ -214,6 +215,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
public static HashMap<Integer, RetrieveFeedsAsyncTask.Type> typePosition = new HashMap<>();
|
||||
private FloatingActionButton federatedTimelines;
|
||||
public static UpdateAccountInfoAsyncTask.SOCIAL social;
|
||||
SparseArray<Fragment> registeredFragments = new SparseArray<>();
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -1351,6 +1353,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
}
|
||||
Helper.switchLayout(BaseMainActivity.this);
|
||||
|
||||
|
||||
if( receive_data != null)
|
||||
LocalBroadcastManager.getInstance(this).unregisterReceiver(receive_data);
|
||||
receive_data = new BroadcastReceiver() {
|
||||
|
@ -1368,6 +1371,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
}
|
||||
}
|
||||
};
|
||||
|
||||
mamageNewIntent(getIntent());
|
||||
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON) {
|
||||
|
@ -1602,6 +1606,8 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void refreshFilters(){
|
||||
if(homeFragment != null)
|
||||
homeFragment.refreshFilter();
|
||||
|
@ -2383,8 +2389,10 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
@NonNull
|
||||
@Override
|
||||
public Object instantiateItem(@NonNull ViewGroup container, int position) {
|
||||
Fragment createdFragment = (Fragment) super.instantiateItem(container, position);
|
||||
registeredFragments.put(position, createdFragment);
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON) {
|
||||
Fragment createdFragment = (Fragment) super.instantiateItem(container, position);
|
||||
|
||||
// save the appropriate reference depending on position
|
||||
if (position == 0) {
|
||||
homeFragment = (DisplayStatusFragment) createdFragment;
|
||||
|
@ -2399,13 +2407,15 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
artFragment = (DisplayStatusFragment) createdFragment;
|
||||
|
||||
}
|
||||
return createdFragment;
|
||||
}else if( social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE){
|
||||
return super.instantiateItem(container, position);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
return createdFragment;
|
||||
}
|
||||
@Override
|
||||
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
|
||||
registeredFragments.remove(position);
|
||||
super.destroyItem(container, position, object);
|
||||
}
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mNumOfTabs;
|
||||
|
|
|
@ -15,8 +15,11 @@ package fr.gouv.etalab.mastodon.client;
|
|||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
@ -1738,11 +1741,21 @@ public class API {
|
|||
return -1;
|
||||
}
|
||||
if(statusAction != StatusAction.UNSTATUS ) {
|
||||
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context);
|
||||
httpsConnection.post(getAbsoluteUrl(action), 60, params, prefKeyOauthTokenT);
|
||||
String resp = httpsConnection.post(getAbsoluteUrl(action), 60, params, prefKeyOauthTokenT);
|
||||
actionCode = httpsConnection.getActionCode();
|
||||
if( statusAction == StatusAction.REBLOG || statusAction == StatusAction.UNREBLOG || statusAction == StatusAction.FAVOURITE || statusAction == StatusAction.UNFAVOURITE) {
|
||||
Bundle b = new Bundle();
|
||||
try {
|
||||
Status status1 = parseStatuses(context, new JSONObject(resp));
|
||||
b.putParcelable("status", status1);
|
||||
} catch (JSONException ignored) {}
|
||||
b.putSerializable("action", statusAction);
|
||||
Intent intentBC = new Intent(Helper.RECEIVE_ACTION);
|
||||
intentBC.putExtras(b);
|
||||
LocalBroadcastManager.getInstance(context).sendBroadcast(intentBC);
|
||||
}
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
|
|
|
@ -2700,6 +2700,28 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
}
|
||||
}
|
||||
|
||||
public void notifyStatusWithActionChanged(Status status){
|
||||
for (int i = 0; i < statusListAdapter.getItemCount(); i++) {
|
||||
//noinspection ConstantConditions
|
||||
if (statusListAdapter.getItemAt(i) != null && statusListAdapter.getItemAt(i).getId().equals(status.getId())) {
|
||||
try {
|
||||
int countFav = statuses.get(i).getFavourites_count() -1;
|
||||
if( countFav < 0)
|
||||
countFav = 0;
|
||||
int countReblog = statuses.get(i).getReblogs_count() -1;
|
||||
if( countReblog < 0)
|
||||
countReblog = 0;
|
||||
statuses.get(i).setFavourited(status.isFavourited());
|
||||
statuses.get(i).setFavourites_count(countFav);
|
||||
statuses.get(i).setReblogged(status.isReblogged());
|
||||
statuses.get(i).setReblogs_count(countReblog);
|
||||
statusListAdapter.notifyItemChanged(i);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onRetrieveEmoji(Status status, boolean fromTranslation) {
|
||||
|
|
|
@ -15,8 +15,10 @@ package fr.gouv.etalab.mastodon.fragments;
|
|||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.os.AsyncTask;
|
||||
|
@ -26,6 +28,7 @@ import android.os.Looper;
|
|||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
|
@ -107,12 +110,11 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
private String initialBookMark;
|
||||
private boolean fetchMoreButtonDisplayed;
|
||||
private TagTimeline tagTimeline;
|
||||
|
||||
private String updatedBookMark;
|
||||
private String lastReadToot;
|
||||
private boolean ischannel;
|
||||
private boolean ownVideos;
|
||||
|
||||
private BroadcastReceiver receive_action;
|
||||
public DisplayStatusFragment(){
|
||||
}
|
||||
|
||||
|
@ -204,7 +206,23 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
mLayoutManager = new LinearLayoutManager(context);
|
||||
lv_status.setLayoutManager(mLayoutManager);
|
||||
|
||||
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON) {
|
||||
|
||||
if( receive_action != null)
|
||||
LocalBroadcastManager.getInstance(context).unregisterReceiver(receive_action);
|
||||
receive_action = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
Bundle b = intent.getExtras();
|
||||
assert b != null;
|
||||
Status status = b.getParcelable("status");
|
||||
if( status != null) {
|
||||
applyAction(status);
|
||||
}
|
||||
}
|
||||
};
|
||||
LocalBroadcastManager.getInstance(context).registerReceiver(receive_action, new IntentFilter(Helper.RECEIVE_ACTION));
|
||||
}
|
||||
|
||||
if( type == RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE && search_peertube != null)
|
||||
((Activity)context).setTitle(remoteInstance + " - " + search_peertube);
|
||||
|
@ -408,6 +426,9 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
super.onDestroy();
|
||||
if(asyncTask != null && asyncTask.getStatus() == AsyncTask.Status.RUNNING)
|
||||
asyncTask.cancel(true);
|
||||
Log.v(Helper.TAG,type + " - destroy: " + receive_action);
|
||||
if( receive_action != null)
|
||||
LocalBroadcastManager.getInstance(context).unregisterReceiver(receive_action);
|
||||
}
|
||||
|
||||
|
||||
|
@ -916,4 +937,11 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
lastReadToot = this.statuses.get(0).getId();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void applyAction(Status status){
|
||||
if( statusListAdapter != null && this.statuses != null && this.statuses.contains(status)){
|
||||
statusListAdapter.notifyStatusWithActionChanged(status);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -384,6 +384,7 @@ public class Helper {
|
|||
public static final String INTENT_BACKUP_FINISH = "intent_backup_finish";
|
||||
//Receiver
|
||||
public static final String RECEIVE_DATA = "receive_data";
|
||||
public static final String RECEIVE_ACTION = "receive_action";
|
||||
public static final String RECEIVE_HOME_DATA = "receive_home_data";
|
||||
public static final String RECEIVE_FEDERATED_DATA = "receive_federated_data";
|
||||
public static final String RECEIVE_LOCAL_DATA = "receive_local_data";
|
||||
|
|
Loading…
Reference in New Issue