Fix crash when adding media

This commit is contained in:
Thomas 2020-07-08 09:48:45 +02:00
parent 481c1ae49b
commit 497ff297d8
21 changed files with 188 additions and 136 deletions

View File

@ -69,6 +69,11 @@
android:name="app.fedilab.android.services.BackupNotificationInDataBaseService"
android:exported="false" />
<receiver android:name=".services.UpgradeReceiver">
<intent-filter>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
</intent-filter>
</receiver>
<receiver
android:name="app.fedilab.android.services.RestartLiveNotificationReceiver"
android:exported="false">
@ -527,5 +532,6 @@
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
</application>
</manifest>

View File

@ -7,7 +7,6 @@ import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
import android.transition.Explode;
import android.view.ActionMode;
import android.view.View;
import android.view.Window;

View File

@ -169,8 +169,7 @@ public class LoginActivity extends BaseActivity {
e.printStackTrace();
}
}).start();
}
else {
} else {
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);

View File

@ -14,7 +14,6 @@
* see <http://www.gnu.org/licenses>. */
package app.fedilab.android.activities;
import android.app.Activity;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Intent;

View File

@ -1322,13 +1322,10 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate,
final ImageView imageView = new ImageView(TootActivity.this);
try {
imageView.setId(Integer.parseInt(attachment.getId()));
}catch (NumberFormatException e){
Random rand = new Random();
int n = rand.nextInt(1000000);
int n = rand.nextInt(10000000);
imageView.setId(n);
}
attachment.setViewId(n);
if (social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
if (successfullyUploadedFiles != null && successfullyUploadedFiles.size() > 0) {
@ -2416,7 +2413,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate,
dialog.setPositiveButton(R.string.yes, (dialog12, which) -> {
View namebar = findViewById(viewId);
for (Attachment attachment : attachments) {
if (Integer.parseInt(attachment.getId()) == viewId) {
if (attachment.getViewId() == viewId) {
attachments.remove(attachment);
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
boolean show_media_urls = sharedpreferences.getBoolean(Helper.SET_MEDIA_URLS, false);

View File

@ -30,7 +30,6 @@ import app.fedilab.android.client.Entities.Peertube;
import app.fedilab.android.client.Entities.RemoteInstance;
import app.fedilab.android.client.Entities.Results;
import app.fedilab.android.client.Entities.RetrieveFeedsParam;
import app.fedilab.android.client.Entities.Status;
import app.fedilab.android.client.GNUAPI;
import app.fedilab.android.client.PeertubeAPI;
import app.fedilab.android.helper.FilterToots;

View File

@ -974,7 +974,8 @@ public class API {
status.setVisibility("public");
}
status.setContent(context, resobj.getString("text"));
} catch (JSONException ignored) {}
} catch (JSONException ignored) {
}
return status;
}

View File

@ -37,6 +37,7 @@ public class Attachment implements Parcelable {
}
};
private String id;
private int viewId;
private String type;
private String url;
private String remote_url;
@ -50,8 +51,17 @@ public class Attachment implements Parcelable {
}
public int getViewId() {
return viewId;
}
public void setViewId(int viewId) {
this.viewId = viewId;
}
protected Attachment(Parcel in) {
this.id = in.readString();
this.viewId = in.readInt();
this.type = in.readString();
this.url = in.readString();
this.remote_url = in.readString();
@ -142,6 +152,7 @@ public class Attachment implements Parcelable {
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(this.id);
dest.writeInt(this.viewId);
dest.writeString(this.type);
dest.writeString(this.url);
dest.writeString(this.remote_url);

View File

@ -47,7 +47,6 @@ import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.transition.Transition;
import com.cleveroad.audiovisualization.DbmHandler;
@ -197,6 +196,7 @@ public class MediaSliderFragment extends Fragment implements MediaPlayer.OnCompl
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
imageView.setTransitionName(attachment.getUrl());
}
if (Helper.isValidContextForGlide(context)) {
Glide.with(context)
.asBitmap()
.dontTransform()
@ -219,6 +219,7 @@ public class MediaSliderFragment extends Fragment implements MediaPlayer.OnCompl
imageView.setVisibility(View.VISIBLE);
pbar_inf.setIndeterminate(true);
loader.setVisibility(View.VISIBLE);
if (Helper.isValidContextForGlide(context)) {
Glide.with(context)
.asBitmap()
.dontTransform()
@ -245,13 +246,16 @@ public class MediaSliderFragment extends Fragment implements MediaPlayer.OnCompl
}
}
);
}
}, 1000);
} else if (attachment.getType().toLowerCase().compareTo("image") == 0 && attachment.getUrl().endsWith(".gif")) {
loader.setVisibility(View.GONE);
if (Helper.isValidContextForGlide(context)) {
Glide.with(context)
.load(url).into(imageView);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
scheduleStartPostponedTransition(imageView);
}
@ -271,6 +275,7 @@ public class MediaSliderFragment extends Fragment implements MediaPlayer.OnCompl
}
}
);
}
switch (type.toLowerCase()) {
case "video":
case "gifv":
@ -427,7 +432,6 @@ public class MediaSliderFragment extends Fragment implements MediaPlayer.OnCompl
} catch (Exception ignored) {
}
}
stopTimer();
}

View File

@ -2080,7 +2080,9 @@ public class Helper {
*/
public static SpannableString clickableElementsDescription(final Context context, String fullContent) {
if (fullContent == null) {
return new SpannableString("");
}
SpannableString spannableString;
SpannableString spannableStringT = new SpannableString(fullContent);
Pattern aLink = Pattern.compile("(<\\s?a\\s?href=\"https?://([\\da-z.-]+\\.[a-z.]{2,10})/(@[/\\w._-]*)\"\\s?[^.]*<\\s?/\\s?a\\s?>)");

View File

@ -1,4 +1,39 @@
package app.fedilab.android.services;
/* Copyright 2020 Thomas Schneider
*
* This file is a part of Fedilab
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
* see <http://www.gnu.org/licenses>. */
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class UpgradeReceiver {
public class UpgradeReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if( intent.getAction() != null && intent.getAction().compareTo(Intent.ACTION_MY_PACKAGE_REPLACED) == 0) {
Intent streamingServiceIntent = new Intent(context, LiveNotificationDelayedService.class);
streamingServiceIntent.putExtra("stop", true);
try {
context.startService(streamingServiceIntent);
} catch (Exception ignored) {}
streamingServiceIntent = new Intent(context, LiveNotificationService.class);
streamingServiceIntent.putExtra("stop", true);
try {
context.startService(streamingServiceIntent);
} catch (Exception ignored) {}
}
}
}