Some fixes with boost/fav
This commit is contained in:
parent
273ae2a0d6
commit
95520e9133
|
@ -45,6 +45,7 @@ import es.dmoral.toasty.Toasty;
|
|||
import fr.gouv.etalab.mastodon.R;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveContextAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.UpdateAccountInfoAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.client.API;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Context;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Error;
|
||||
|
@ -126,8 +127,9 @@ public class ShowConversationActivity extends BaseActivity implements OnRetriev
|
|||
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(status);
|
||||
statusListAdapter.notifyStatusWithActionChanged(statusAction, status);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -167,7 +167,7 @@ public class WebviewConnectActivity extends BaseActivity {
|
|||
String token = resobj.get("access_token").toString();
|
||||
String refresh_token = null;
|
||||
if( resobj.has("refresh_token"))
|
||||
refresh_token = resobj.get("access_token").toString();
|
||||
refresh_token = resobj.get("refresh_token").toString();
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, token);
|
||||
|
|
|
@ -61,11 +61,7 @@ public class UpdateAccountInfoByIDAsyncTask extends AsyncTask<Void, Void, Void>
|
|||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON)
|
||||
account = new API(this.contextReference.get()).getAccount(userId);
|
||||
else if( social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) {
|
||||
try {
|
||||
account = new PeertubeAPI(this.contextReference.get()).verifyCredentials();
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
account = new PeertubeAPI(this.contextReference.get()).verifyCredentials();
|
||||
account.setSocial("PEERTUBE");
|
||||
|
|
|
@ -20,6 +20,7 @@ import android.database.sqlite.SQLiteDatabase;
|
|||
import android.os.Build;
|
||||
import android.text.Html;
|
||||
import android.text.SpannableString;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.common.io.ByteStreams;
|
||||
|
||||
|
@ -1419,6 +1420,7 @@ public class HttpsConnection {
|
|||
postData.append('=');
|
||||
postData.append(String.valueOf(param.getValue()));
|
||||
}
|
||||
Log.v(Helper.TAG,"postData.toString(): " + postData.toString());
|
||||
byte[] postDataBytes = postData.toString().getBytes("UTF-8");
|
||||
|
||||
if (proxy != null)
|
||||
|
|
|
@ -856,15 +856,31 @@ public class NotificationsListAdapter extends RecyclerView.Adapter implements On
|
|||
}
|
||||
|
||||
|
||||
public void notifyNotificationWithActionChanged(Status status){
|
||||
public void notifyNotificationWithActionChanged(API.StatusAction statusAction, 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){
|
||||
|
||||
int favCount = notifications.get(i).getStatus().getFavourites_count();
|
||||
int boostCount = notifications.get(i).getStatus().getReblogs_count();
|
||||
if( statusAction == API.StatusAction.REBLOG)
|
||||
boostCount++;
|
||||
else if( statusAction == API.StatusAction.UNREBLOG)
|
||||
boostCount--;
|
||||
else if( statusAction == API.StatusAction.FAVOURITE)
|
||||
favCount++;
|
||||
else if( statusAction == API.StatusAction.UNFAVOURITE)
|
||||
favCount--;
|
||||
if( boostCount < 0 )
|
||||
boostCount = 0;
|
||||
if( favCount < 0 )
|
||||
favCount = 0;
|
||||
|
||||
notifications.get(i).getStatus().setFavourited(status.isFavourited());
|
||||
notifications.get(i).getStatus().setFavourites_count(status.getFavourites_count());
|
||||
notifications.get(i).getStatus().setFavourites_count(favCount);
|
||||
notifications.get(i).getStatus().setReblogged(status.isReblogged());
|
||||
notifications.get(i).getStatus().setReblogs_count(status.getReblogs_count());
|
||||
notifications.get(i).getStatus().setReblogs_count(boostCount);
|
||||
}
|
||||
notificationsListAdapter.notifyItemChanged(i);
|
||||
} catch (Exception ignored) {
|
||||
|
|
|
@ -2626,55 +2626,6 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
position++;
|
||||
}
|
||||
}
|
||||
|
||||
/*if( statusAction == API.StatusAction.REBLOG){
|
||||
int position = 0;
|
||||
for(Status status: statuses){
|
||||
if( status.getId().equals(targetedId)) {
|
||||
status.setReblogs_count(status.getReblogs_count() + 1);
|
||||
statusListAdapter.notifyItemChanged(position);
|
||||
break;
|
||||
}
|
||||
position++;
|
||||
}
|
||||
}else if( statusAction == API.StatusAction.UNREBLOG){
|
||||
int position = 0;
|
||||
for(Status status: statuses){
|
||||
if( status.getId().equals(targetedId)) {
|
||||
if( status.getReblogs_count() - 1 >= 0)
|
||||
status.setReblogs_count(status.getReblogs_count() - 1);
|
||||
statusListAdapter.notifyItemChanged(position);
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
//Remove the status from cache also
|
||||
try {
|
||||
new StatusCacheDAO(context, db).remove(StatusCacheDAO.ARCHIVE_CACHE,status);
|
||||
}catch (Exception ignored){}
|
||||
break;
|
||||
}
|
||||
position++;
|
||||
}
|
||||
}else if( statusAction == API.StatusAction.FAVOURITE){
|
||||
int position = 0;
|
||||
for(Status status: statuses){
|
||||
if( status.getId().equals(targetedId)) {
|
||||
status.setFavourites_count(status.getFavourites_count() + 1);
|
||||
statusListAdapter.notifyItemChanged(position);
|
||||
break;
|
||||
}
|
||||
position++;
|
||||
}
|
||||
}else if( statusAction == API.StatusAction.UNFAVOURITE){
|
||||
int position = 0;
|
||||
for(Status status: statuses){
|
||||
if( status.getId().equals(targetedId)) {
|
||||
if( status.getFavourites_count() - 1 >= 0)
|
||||
status.setFavourites_count(status.getFavourites_count() - 1);
|
||||
statusListAdapter.notifyItemChanged(position);
|
||||
break;
|
||||
}
|
||||
position++;
|
||||
}
|
||||
}*/
|
||||
if( statusAction == API.StatusAction.PEERTUBEDELETECOMMENT){
|
||||
int position = 0;
|
||||
for(Status status: statuses){
|
||||
|
@ -2700,15 +2651,29 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
}
|
||||
}
|
||||
|
||||
public void notifyStatusWithActionChanged(Status status){
|
||||
public void notifyStatusWithActionChanged(API.StatusAction statusAction, 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 favCount = statuses.get(i).getFavourites_count();
|
||||
int boostCount = statuses.get(i).getReblogs_count();
|
||||
if( statusAction == API.StatusAction.REBLOG)
|
||||
boostCount++;
|
||||
else if( statusAction == API.StatusAction.UNREBLOG)
|
||||
boostCount--;
|
||||
else if( statusAction == API.StatusAction.FAVOURITE)
|
||||
favCount++;
|
||||
else if( statusAction == API.StatusAction.UNFAVOURITE)
|
||||
favCount--;
|
||||
if( boostCount < 0 )
|
||||
boostCount = 0;
|
||||
if( favCount < 0 )
|
||||
favCount = 0;
|
||||
statuses.get(i).setFavourited(status.isFavourited());
|
||||
statuses.get(i).setFavourites_count(status.getFavourites_count());
|
||||
statuses.get(i).setFavourites_count(favCount);
|
||||
statuses.get(i).setReblogged(status.isReblogged());
|
||||
statuses.get(i).setReblogs_count(status.getReblogs_count());
|
||||
statuses.get(i).setReblogs_count(boostCount);
|
||||
statusListAdapter.notifyItemChanged(i);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ 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.API;
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Notification;
|
||||
|
@ -143,8 +144,9 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
|||
Bundle b = intent.getExtras();
|
||||
assert b != null;
|
||||
Status status = b.getParcelable("status");
|
||||
API.StatusAction statusAction = (API.StatusAction) b.getSerializable("action");
|
||||
if( status != null) {
|
||||
notificationsListAdapter.notifyNotificationWithActionChanged(status);
|
||||
notificationsListAdapter.notifyNotificationWithActionChanged(statusAction, status);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -51,6 +51,7 @@ 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,8 +218,9 @@ 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(status);
|
||||
statusListAdapter.notifyStatusWithActionChanged(statusAction, status);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue