Some fixes
This commit is contained in:
parent
9cde0eeaf3
commit
b60216a8c1
|
@ -1752,7 +1752,6 @@ public class API {
|
|||
b.putParcelable("status", status1);
|
||||
b.putSerializable("action", statusAction);
|
||||
} catch (JSONException ignored) {}
|
||||
b.putSerializable("action", statusAction);
|
||||
Intent intentBC = new Intent(Helper.RECEIVE_ACTION);
|
||||
intentBC.putExtras(b);
|
||||
LocalBroadcastManager.getInstance(context).sendBroadcast(intentBC);
|
||||
|
|
|
@ -855,6 +855,24 @@ public class NotificationsListAdapter extends RecyclerView.Adapter implements On
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public void notifyNotificationWithActionChanged(Status status){
|
||||
for (int i = 0; i < notificationsListAdapter.getItemCount(); i++) {
|
||||
if (notificationsListAdapter.getItemAt(i) != null && notificationsListAdapter.getItemAt(i).getType().toLowerCase().equals("mention") && notificationsListAdapter.getItemAt(i).getStatus() != null && notificationsListAdapter.getItemAt(i).getStatus().getId().equals(status.getId())) {
|
||||
try {
|
||||
if( notifications.get(i).getStatus() != null){
|
||||
notifications.get(i).getStatus().setFavourited(status.isFavourited());
|
||||
notifications.get(i).getStatus().setFavourites_count(status.getFavourites_count());
|
||||
notifications.get(i).getStatus().setReblogged(status.isReblogged());
|
||||
notifications.get(i).getStatus().setReblogs_count(status.getReblogs_count());
|
||||
}
|
||||
notificationsListAdapter.notifyItemChanged(i);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
|
|
|
@ -2700,31 +2700,15 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
}
|
||||
}
|
||||
|
||||
public void notifyStatusWithActionChanged(API.StatusAction statusAction, Status status){
|
||||
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 j;
|
||||
int countFav = statuses.get(i).getFavourites_count();
|
||||
int countReblog = statuses.get(i).getReblogs_count();
|
||||
if( statusAction == API.StatusAction.UNFAVOURITE){
|
||||
countFav--;
|
||||
if( countFav < 0)
|
||||
countFav = 0;
|
||||
}else if( statusAction == API.StatusAction.FAVOURITE){
|
||||
countFav++;
|
||||
}else if( statusAction == API.StatusAction.UNREBLOG){
|
||||
countReblog--;
|
||||
if( countReblog < 0)
|
||||
countReblog = 0;
|
||||
}else if( statusAction == API.StatusAction.REBLOG){
|
||||
countReblog++;
|
||||
}
|
||||
statuses.get(i).setFavourited(status.isFavourited());
|
||||
statuses.get(i).setFavourites_count(countFav);
|
||||
statuses.get(i).setFavourites_count(status.getFavourites_count());
|
||||
statuses.get(i).setReblogged(status.isReblogged());
|
||||
statuses.get(i).setReblogs_count(countReblog);
|
||||
statuses.get(i).setReblogs_count(status.getReblogs_count());
|
||||
statusListAdapter.notifyItemChanged(i);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
|
|
@ -14,7 +14,10 @@ package fr.gouv.etalab.mastodon.fragments;
|
|||
* You should have received a copy of the GNU General Public License along with Mastalab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
|
@ -23,6 +26,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.DividerItemDecoration;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
|
@ -41,9 +45,11 @@ import fr.gouv.etalab.mastodon.R;
|
|||
import fr.gouv.etalab.mastodon.activities.MainActivity;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveMissingNotificationsAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveNotificationsAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.UpdateAccountInfoAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Notification;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Status;
|
||||
import fr.gouv.etalab.mastodon.drawers.NotificationsListAdapter;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveMissingNotificationsInterface;
|
||||
|
@ -72,6 +78,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
|||
private String userId, instance;
|
||||
private SharedPreferences sharedpreferences;
|
||||
LinearLayoutManager mLayoutManager;
|
||||
private BroadcastReceiver receive_action;
|
||||
|
||||
public DisplayNotificationsFragment(){
|
||||
}
|
||||
|
@ -125,6 +132,24 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
|||
}
|
||||
});
|
||||
|
||||
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) {
|
||||
notificationsListAdapter.notifyNotificationWithActionChanged(status);
|
||||
}
|
||||
}
|
||||
};
|
||||
LocalBroadcastManager.getInstance(context).registerReceiver(receive_action, new IntentFilter(Helper.RECEIVE_ACTION));
|
||||
}
|
||||
|
||||
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
|
@ -198,6 +223,8 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
|||
super.onDestroy();
|
||||
if(asyncTask != null && asyncTask.getStatus() == AsyncTask.Status.RUNNING)
|
||||
asyncTask.cancel(true);
|
||||
if( receive_action != null)
|
||||
LocalBroadcastManager.getInstance(context).unregisterReceiver(receive_action);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -51,7 +51,6 @@ import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask;
|
|||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveMissingFeedsAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.RetrievePeertubeSearchAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.UpdateAccountInfoAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.client.API;
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Conversation;
|
||||
|
@ -217,9 +216,8 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
Bundle b = intent.getExtras();
|
||||
assert b != null;
|
||||
Status status = b.getParcelable("status");
|
||||
API.StatusAction statusAction = (API.StatusAction)b.getSerializable("action");
|
||||
if( status != null) {
|
||||
statusListAdapter.notifyStatusWithActionChanged(statusAction, status);
|
||||
statusListAdapter.notifyStatusWithActionChanged(status);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue