summaryrefslogtreecommitdiffstats
path: root/app/src/main/java/fr/gouv/etalab
diff options
context:
space:
mode:
authorstom79 <tschneider.ac@gmail.com>2019-01-12 09:26:18 +0100
committerstom79 <tschneider.ac@gmail.com>2019-01-12 09:26:18 +0100
commit95520e9133fe5a071397fe81dbede0c5614f826d (patch)
tree3e296cf652d47a3538cf1bf3c64ff813ef437df9 /app/src/main/java/fr/gouv/etalab
parent273ae2a0d65b439e087f143908fcb2bf8e49e7b5 (diff)
Some fixes with boost/fav
Diffstat (limited to 'app/src/main/java/fr/gouv/etalab')
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowConversationActivity.java4
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/activities/WebviewConnectActivity.java2
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/UpdateAccountInfoByIDAsyncTask.java6
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/client/HttpsConnection.java2
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/drawers/NotificationsListAdapter.java22
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java69
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayNotificationsFragment.java4
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java4
8 files changed, 49 insertions, 64 deletions
diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowConversationActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowConversationActivity.java
index 4d1f3e5dd..9678e1125 100644
--- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowConversationActivity.java
+++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/ShowConversationActivity.java
@@ -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);
}
}
};
diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/WebviewConnectActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/WebviewConnectActivity.java
index 29e572ad2..06b40c9a4 100644
--- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/WebviewConnectActivity.java
+++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/WebviewConnectActivity.java
@@ -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);
diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/UpdateAccountInfoByIDAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/UpdateAccountInfoByIDAsyncTask.java
index dfbec8bf1..574068f90 100644
--- a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/UpdateAccountInfoByIDAsyncTask.java
+++ b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/UpdateAccountInfoByIDAsyncTask.java
@@ -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");
diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/HttpsConnection.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/HttpsConnection.java
index 930105d69..a4f3c89f4 100644
--- a/app/src/main/java/fr/gouv/etalab/mastodon/client/HttpsConnection.java
+++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/HttpsConnection.java
@@ -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)
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 6cdb56157..9a8d2524c 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
@@ -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) {
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 aa06ae2ce..6eb4ab75f 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
@@ -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) {
}
diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayNotificationsFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayNotificationsFragment.java
index b75b22da3..e9d093235 100644
--- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayNotificationsFragment.java
+++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayNotificationsFragment.java
@@ -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);
}
}
};
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 d22a32f45..53bc01f5f 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
@@ -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);
}
}
};