Commit 4abc8aa3 authored by Thomas's avatar Thomas
Browse files

Fix some issues

parent 3b35639e
Pipeline #294116 passed with stage
in 15 minutes and 7 seconds
......@@ -16,6 +16,7 @@ package app.fedilab.android.activities;
import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
......@@ -185,6 +186,7 @@ public class EditProfileActivity extends BaseActivity implements OnRetrieveAccou
}
@SuppressLint("CutPasteId")
@Override
public void onRetrieveAccount(Account account, Error error) {
if (error != null) {
......@@ -312,36 +314,33 @@ public class EditProfileActivity extends BaseActivity implements OnRetrieveAccou
Intent getIntent = new Intent(Intent.ACTION_GET_CONTENT);
getIntent.setType("image/*");
Intent pickIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
pickIntent.setType("image/*");
Intent pickIntent = new Intent(Intent.ACTION_PICK);
pickIntent.setDataAndType(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI,"image/*");
Intent chooserIntent = Intent.createChooser(getIntent, getString(R.string.toot_select_image));
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{pickIntent});
startActivityForResult(chooserIntent, PICK_IMAGE_HEADER);
});
set_change_profile_picture.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (ContextCompat.checkSelfPermission(EditProfileActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) !=
PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(EditProfileActivity.this,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE_PICTURE);
return;
}
set_change_profile_picture.setOnClickListener(v -> {
if (ContextCompat.checkSelfPermission(EditProfileActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) !=
PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(EditProfileActivity.this,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE_PICTURE);
return;
}
Intent getIntent = new Intent(Intent.ACTION_GET_CONTENT);
getIntent.setType("image/*");
Intent getIntent = new Intent(Intent.ACTION_GET_CONTENT);
getIntent.setType("image/*");
Intent pickIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
pickIntent.setType("image/*");
Intent pickIntent = new Intent(Intent.ACTION_PICK);
pickIntent.setDataAndType(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
Intent chooserIntent = Intent.createChooser(getIntent, getString(R.string.toot_select_image));
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{pickIntent});
startActivityForResult(chooserIntent, PICK_IMAGE_PROFILE);
}
Intent chooserIntent = Intent.createChooser(getIntent, getString(R.string.toot_select_image));
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{pickIntent});
startActivityForResult(chooserIntent, PICK_IMAGE_PROFILE);
});
if (!EditProfileActivity.this.isFinishing()) {
......
......@@ -589,8 +589,7 @@ public class LoginActivity extends BaseActivity {
String refresh_token = null;
if (resobj.has("refresh_token"))
refresh_token = resobj.getString("refresh_token");
SharedPreferences sharedpreferences1 = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences1.edit();
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, token);
editor.apply();
//Update the account with the token;
......@@ -601,10 +600,9 @@ public class LoginActivity extends BaseActivity {
} else {
try {
resobj = new JSONObject(response);
Account account = GNUAPI.parseAccountResponse(LoginActivity.this, resobj);
Account account = GNUAPI.parseAccountResponse(resobj);
account.setToken(basicAuth);
SharedPreferences sharedpreferences1 = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences1.edit();
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, basicAuth);
account.setInstance(instance);
......
......@@ -166,7 +166,7 @@ public class PhotoEditorActivity extends BaseActivity implements OnPhotoEditorLi
//Set Image Dynamically
try {
mPhotoEditorView.getSource().setImageURI(uri);
}catch (Exception e){
} catch (Exception e) {
Toasty.error(PhotoEditorActivity.this, getString(R.string.error)).show();
}
......
......@@ -36,6 +36,7 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
......@@ -109,11 +110,11 @@ public class ShowConversationActivity extends BaseActivity implements OnRetrieve
loader.setVisibility(View.VISIBLE);
detailsStatus.setFocused(true);
//Some spannable
Status.fillSpan(ShowConversationActivity.this, detailsStatus);
Status.fillSpan(new WeakReference<>(ShowConversationActivity.this), detailsStatus);
if (detailsStatus.getPoll() != null) {
Status.makeEmojiPoll(ShowConversationActivity.this, detailsStatus.getPoll());
Status.makeEmojiPoll(new WeakReference<>(ShowConversationActivity.this), detailsStatus.getPoll());
}
Account.makeAccountNameEmoji(ShowConversationActivity.this, detailsStatus.getAccount());
Account.makeAccountNameEmoji(new WeakReference<>(ShowConversationActivity.this), detailsStatus.getAccount());
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON) {
......
......@@ -316,7 +316,7 @@ public class SlideMediaActivity extends BaseActivity implements OnDownloadInterf
public void togglePlaying(View v) {
if (mCurrentFragment != null) {
mCurrentFragment.togglePlaying(v);
mCurrentFragment.togglePlaying();
}
}
......
......@@ -369,9 +369,9 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
List<app.fedilab.android.client.Entities.Status> statuses = new StatusCacheDAO(contextReference.get(), db).getAllStatus(StatusCacheDAO.BOOKMARK_CACHE);
if (statuses != null) {
for (app.fedilab.android.client.Entities.Status status : statuses) {
app.fedilab.android.client.Entities.Status.fillSpan(contextReference.get(), status);
app.fedilab.android.client.Entities.Status.makeEmojiPoll(contextReference.get(), status.getReblog() != null ? status.getReblog().getPoll() : status.getPoll());
Account.makeAccountNameEmoji(contextReference.get(), status.getReblog() != null ? status.getReblog().getAccount() : status.getAccount());
app.fedilab.android.client.Entities.Status.fillSpan(contextReference, status);
app.fedilab.android.client.Entities.Status.makeEmojiPoll(contextReference, status.getReblog() != null ? status.getReblog().getPoll() : status.getPoll());
Account.makeAccountNameEmoji(contextReference, status.getReblog() != null ? status.getReblog().getAccount() : status.getAccount());
}
} else {
statuses = new ArrayList<>();
......
......@@ -36,6 +36,7 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.lang.ref.WeakReference;
import java.net.URLEncoder;
import java.net.UnknownHostException;
import java.security.KeyManagementException;
......@@ -297,7 +298,7 @@ public class API {
* @param resobj JSONObject
* @return Peertube
*/
public static Peertube parsePeertube(Context context, String instance, JSONObject resobj) {
public static Peertube parsePeertube(String instance, JSONObject resobj) {
Peertube peertube = new Peertube();
try {
peertube.setId(resobj.get("id").toString());
......@@ -332,7 +333,7 @@ public class API {
* @param resobj JSONObject
* @return Peertube
*/
private static Peertube parseSinglePeertube(Context context, String instance, JSONObject resobj) {
private static Peertube parseSinglePeertube(String instance, JSONObject resobj) {
Peertube peertube = new Peertube();
try {
peertube.setId(resobj.get("id").toString());
......@@ -672,7 +673,7 @@ public class API {
} catch (JSONException | ParseException e) {
e.printStackTrace();
}
Status.fillSpan(context, announcement);
Status.fillSpan(new WeakReference<>(context), announcement);
return announcement;
}
......@@ -717,7 +718,7 @@ public class API {
} catch (JSONException | ParseException e) {
e.printStackTrace();
}
Status.makeEmojiPoll(context, poll);
Status.makeEmojiPoll(new WeakReference<>(context), poll);
return poll;
}
......@@ -754,7 +755,9 @@ public class API {
} else {
status.setSensitive(false);
}
status.setSpoiler_text(resobj.get("spoiler_text").toString());
if (resobj.has("spoiler_text")) {
status.setSpoiler_text(resobj.get("spoiler_text").toString());
}
try {
status.setVisibility(resobj.get("visibility").toString());
} catch (Exception e) {
......@@ -775,8 +778,9 @@ public class API {
}
status.setReactions(reactions);
status.setUrl(resobj.get("url").toString());
if (resobj.has("url")) {
status.setUrl(resobj.get("url").toString());
}
ArrayList<Attachment> attachments = new ArrayList<>();
//Retrieves attachments
if (resobj.has("media_attachments")) {
......@@ -807,41 +811,46 @@ public class API {
status.setMedia_attachments(attachments);
//Retrieves mentions
List<Mention> mentions = new ArrayList<>();
JSONArray arrayMention = resobj.getJSONArray("mentions");
for (int j = 0; j < arrayMention.length(); j++) {
JSONObject menObj = arrayMention.getJSONObject(j);
Mention mention = new Mention();
mention.setId(menObj.get("id").toString());
mention.setUrl(menObj.get("url").toString());
mention.setAcct(menObj.get("acct").toString());
mention.setUsername(menObj.get("username").toString());
mentions.add(mention);
if (resobj.has("mentions")) {
JSONArray arrayMention = resobj.getJSONArray("mentions");
for (int j = 0; j < arrayMention.length(); j++) {
JSONObject menObj = arrayMention.getJSONObject(j);
Mention mention = new Mention();
mention.setId(menObj.get("id").toString());
mention.setUrl(menObj.get("url").toString());
mention.setAcct(menObj.get("acct").toString());
mention.setUsername(menObj.get("username").toString());
mentions.add(mention);
}
}
status.setMentions(mentions);
//Retrieves tags
List<Tag> tags = new ArrayList<>();
JSONArray arrayTag = resobj.getJSONArray("tags");
for (int j = 0; j < arrayTag.length(); j++) {
JSONObject tagObj = arrayTag.getJSONObject(j);
Tag tag = new Tag();
tag.setName(tagObj.get("name").toString());
tag.setUrl(tagObj.get("url").toString());
tags.add(tag);
if (resobj.has("tags")) {
JSONArray arrayTag = resobj.getJSONArray("tags");
for (int j = 0; j < arrayTag.length(); j++) {
JSONObject tagObj = arrayTag.getJSONObject(j);
Tag tag = new Tag();
tag.setName(tagObj.get("name").toString());
tag.setUrl(tagObj.get("url").toString());
tags.add(tag);
}
}
status.setTags(tags);
//Retrieves emjis
List<Emojis> emojiList = new ArrayList<>();
try {
JSONArray emojisTag = resobj.getJSONArray("emojis");
for (int j = 0; j < emojisTag.length(); j++) {
JSONObject emojisObj = emojisTag.getJSONObject(j);
Emojis emojis = parseEmojis(emojisObj);
emojiList.add(emojis);
if (resobj.has("emojis")) {
try {
JSONArray emojisTag = resobj.getJSONArray("emojis");
for (int j = 0; j < emojisTag.length(); j++) {
JSONObject emojisObj = emojisTag.getJSONObject(j);
Emojis emojis = parseEmojis(emojisObj);
emojiList.add(emojis);
}
} catch (Exception ignored) {
}
status.setEmojis(emojiList);
} catch (Exception e) {
status.setEmojis(new ArrayList<>());
}
status.setEmojis(emojiList);
//Retrieve Application
Application application = new Application();
try {
......@@ -905,7 +914,7 @@ public class API {
e.printStackTrace();
}
status.setViewType(context);
Status.fillSpan(context, status);
Status.fillSpan(new WeakReference<>(context), status);
return status;
}
......@@ -1090,7 +1099,7 @@ public class API {
} catch (ParseException e) {
e.printStackTrace();
}
Status.fillSpan(context, status);
Status.fillSpan(new WeakReference<>(context), status);
return status;
}
......@@ -1482,7 +1491,7 @@ public class API {
e.printStackTrace();
}
try {
Account.makeAccountNameEmoji(context, account);
Account.makeAccountNameEmoji(new WeakReference<>(context), account);
} catch (Exception e) {
e.printStackTrace();
}
......@@ -1614,10 +1623,11 @@ public class API {
notification.setType(resobj.get("type").toString());
notification.setCreated_at(Helper.mstStringToDate(resobj.get("created_at").toString()));
notification.setAccount(parseAccountResponse(context, resobj.getJSONObject("account")));
try {
notification.setStatus(parseStatuses(context, resobj.getJSONObject("status")));
} catch (Exception ignored) {
ignored.printStackTrace();
if (resobj.has("status")) {
try {
notification.setStatus(parseStatuses(context, resobj.getJSONObject("status")));
} catch (Exception ignored) {
}
}
notification.setCreated_at(Helper.mstStringToDate(resobj.get("created_at").toString()));
} catch (JSONException ignored) {
......@@ -1761,7 +1771,7 @@ public class API {
if (xpp.getName().compareTo("item") == 0) {
if (status != null) {
status.setAccount(account);
Status.fillSpan(context, status);
Status.fillSpan(new WeakReference<>(context), status);
statuses.add(status);
}
account = null;
......@@ -1783,7 +1793,7 @@ public class API {
while (i < jsonArray.length()) {
JSONObject resobj = jsonArray.getJSONObject(i);
IdentityProof identityProof = parseIdentityProof(context, resobj);
IdentityProof identityProof = parseIdentityProof(resobj);
i++;
identityProofs.add(identityProof);
}
......@@ -1794,7 +1804,7 @@ public class API {
return identityProofs;
}
private IdentityProof parseIdentityProof(Context context, JSONObject jsonObject) {
private IdentityProof parseIdentityProof(JSONObject jsonObject) {
IdentityProof identityProof = new IdentityProof();
try {
identityProof.setProfile_url(jsonObject.getString("profile_url"));
......@@ -3224,7 +3234,7 @@ public class API {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String response = httpsConnection.get(String.format("https://" + instance + "/api/v1/accounts/%s/video-channels", name), 10, null, null);
JSONArray jsonArray = new JSONObject(response).getJSONArray("data");
accounts = parseAccountResponsePeertube(context, instance, jsonArray);
accounts = parseAccountResponsePeertube(instance, jsonArray);
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
e.printStackTrace();
......@@ -3307,7 +3317,7 @@ public class API {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String response = httpsConnection.get(String.format("https://" + instance + "/api/v1/videos/%s", videoId), 10, null, null);
JSONObject jsonObject = new JSONObject(response);
peertube = parseSinglePeertube(context, instance, jsonObject);
peertube = parseSinglePeertube(instance, jsonObject);
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
e.printStackTrace();
......@@ -4553,7 +4563,9 @@ public class API {
Status alreadyCached = new TimelineCacheDAO(context, db).getSingle(status.getId());
Account account = new AccountDAO(context, db).getAccountByToken(prefKeyOauthTokenT);
if (alreadyCached != null) {
new TimelineCacheDAO(context, db).update(status.getId(), response, account.getId(), account.getInstance());
poll = parsePoll(context, new JSONObject(response));
status.setPoll(poll);
new TimelineCacheDAO(context, db).update(status.getId(), Helper.statusToStringStorage(status), account.getId(), account.getInstance());
}
LocalBroadcastManager.getInstance(context).sendBroadcast(intentBC);
return poll;
......@@ -5556,7 +5568,7 @@ public class API {
int i = 0;
while (i < jsonArray.length()) {
JSONObject resobj = jsonArray.getJSONObject(i);
Peertube peertube = parsePeertube(context, instance, resobj);
Peertube peertube = parsePeertube(instance, resobj);
i++;
peertubes.add(peertube);
}
......@@ -5901,7 +5913,7 @@ public class API {
return lists;
}
private List<Account> parseAccountResponsePeertube(Context context, String instance, JSONArray jsonArray) {
private List<Account> parseAccountResponsePeertube(String instance, JSONArray jsonArray) {
List<Account> accounts = new ArrayList<>();
try {
int i = 0;
......
......@@ -47,6 +47,7 @@ import com.bumptech.glide.request.transition.Transition;
import org.jetbrains.annotations.NotNull;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
......@@ -199,7 +200,8 @@ public class Account implements Parcelable {
this.invited_by_account_id = in.readString();
}
public static void makeAccountNameEmoji(final Context context, Account account) {
public static void makeAccountNameEmoji(final WeakReference<Context> contextWeakReference, Account account) {
Context context = contextWeakReference.get();
if ((context instanceof Activity && ((Activity) context).isFinishing()) || account.getDisplay_name() == null)
return;
......
......@@ -571,7 +571,7 @@ public class ManageTimelines {
}
popup.setOnDismissListener(menu12 -> {
if (displayStatusFragment != null && displayStatusFragment.getUserVisibleHint())
if (displayStatusFragment != null && displayStatusFragment.isVisible())
displayStatusFragment.refreshFilter();
});
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
......
......@@ -59,6 +59,7 @@ import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.target.Target;
import com.bumptech.glide.request.transition.Transition;
import java.lang.ref.WeakReference;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
......@@ -263,15 +264,15 @@ public class Status implements Parcelable {
}
public static void fillSpan(Context context, Status status) {
Status.transform(context, status);
Status.makeEmojis(context, status);
Status.makeImage(context, status);
public static void fillSpan(WeakReference<Context> contextWeakReference, Status status) {
Status.transform(contextWeakReference, status);
Status.makeEmojis(contextWeakReference, status);
Status.makeImage(contextWeakReference, status);
}
private static void transform(Context context, Status status) {
private static void transform(WeakReference<Context> contextWeakReference, Status status) {
Context context = contextWeakReference.get();
if (status == null)
return;
SpannableString spannableStringContent, spannableStringCW;
......@@ -849,8 +850,8 @@ public class Status implements Parcelable {
status.setContentSpanTranslated(contentSpanTranslated);
}
private static void makeEmojis(final Context context, Status status) {
private static void makeEmojis(final WeakReference<Context> contextWeakReference, Status status) {
Context context = contextWeakReference.get();
if (context instanceof Activity && ((Activity) context).isFinishing())
return;
if (status.getReblog() != null && status.getReblog().getEmojis() == null)
......@@ -931,7 +932,8 @@ public class Status implements Parcelable {
}
}
public static void makeEmojiPoll(final Context context, Poll poll) {
public static void makeEmojiPoll(final WeakReference<Context> contextWeakReference, Poll poll) {
Context context = contextWeakReference.get();
if ((context instanceof Activity && ((Activity) context).isFinishing()) || poll == null || poll.getOptionsList() == null)
return;
final List<Emojis> emojis = poll.getEmojis();
......@@ -991,8 +993,8 @@ public class Status implements Parcelable {
}
}
private static void makeImage(final Context context, Status status) {
private static void makeImage(final WeakReference<Context> contextWeakReference, Status status) {
Context context = contextWeakReference.get();
if (context instanceof Activity && ((Activity) context).isFinishing())
return;
if (status.getAccount() == null)
......
......@@ -28,6 +28,7 @@ import org.json.JSONObject;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.ref.WeakReference;
import java.net.URLEncoder;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
......@@ -133,7 +134,7 @@ public class GNUAPI {
* @param jsonArray JSONArray
* @return List<Account>
*/
private static List<Account> parseGroups(Context context, JSONArray jsonArray) {
private static List<Account> parseGroups(JSONArray jsonArray) {
List<Account> groups = new ArrayList<>();
try {
......@@ -141,7 +142,7 @@ public class GNUAPI {
while (i < jsonArray.length()) {
JSONObject resobj = jsonArray.getJSONObject(i);
Account group = parseGroups(context, resobj);
Account group = parseGroups(resobj);
i++;
groups.add(group);
}
......@@ -158,7 +159,7 @@ public class GNUAPI {
* @param resobj JSONObject
* @return Account
*/
private static Account parseGroups(Context context, JSONObject resobj) {
private static Account parseGroups(JSONObject resobj) {
Account group = new Account();
try {
group.setId(resobj.get("id").toString());
......@@ -293,9 +294,9 @@ public class GNUAPI {
}
status.setApplication(application);
if (resobj.has("user"))
status.setAccount(parseAccountResponse(context, resobj.getJSONObject("user")));
status.setAccount(parseAccountResponse(resobj.getJSONObject("user")));
else if (resobj.has("sender"))
status.setAccount(parseAccountResponse(context, resobj.getJSONObject("sender")));
status.setAccount(parseAccountResponse(resobj.getJSONObject("sender")));
if (resobj.has("statusnet_html"))
status.setContent(context, resobj.get("statusnet_html").toString());
else if (resobj.has("text"))
......@@ -346,7 +347,7 @@ public class GNUAPI {
e.printStackTrace();
}
status.setViewType(context);
Status.fillSpan(context, status);
Status.fillSpan(new WeakReference<>(context), status);
return status;
}
......@@ -357,7 +358,7 @@ public class GNUAPI {
* @param resobj JSONObject
* @return Account
*/
public static Account parseAccountResponse(Context context, JSONObject resobj) {
public static Account parseAccountResponse(JSONObject resobj) {
Account account = new Account();
try {
......@@ -553,7 +554,7 @@ public class GNUAPI {
}
try {
String response = new HttpsConnection(context, this.instance).get(getAbsoluteUrl("/account/verify_credentials.json"), 60, null, prefKeyOauthTokenT);
account = parseAccountResponse(context, new JSONObject(response));
account = parseAccountResponse(new JSONObject(response));
if (social != null) {
account.setSocial(social.toUpperCase());
}
......@@ -579,7 +580,7 @@ public class GNUAPI {
params.put("user_id", accountId);
try {
String response = new HttpsConnection(context, this.instance).get(getAbsoluteUrl("/users/show.json"), 60, params, prefKeyOauthTokenT);
account = parseAccountResponse(context, new JSONObject(response));
account = parseAccountResponse(new JSONObject(response));
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);