diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 6da165b8..30591a71 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -35,7 +35,6 @@ diff --git a/app/src/main/java/app/fedilab/android/activities/ComposeActivity.java b/app/src/main/java/app/fedilab/android/activities/ComposeActivity.java index d3aecaf2..fc3d8000 100644 --- a/app/src/main/java/app/fedilab/android/activities/ComposeActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/ComposeActivity.java @@ -122,7 +122,7 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana for (Status status : statusList) { if (status.media_attachments != null && status.media_attachments.size() > 0) { for (Attachment attachment : status.media_attachments) { - if (attachment.local_path.equalsIgnoreCase(imgpath)) { + if (attachment.local_path != null && attachment.local_path.equalsIgnoreCase(imgpath)) { if (focusX != -2) { attachment.focus = focusX + "," + focusY; } @@ -492,7 +492,7 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana visibility = b.getString(Helper.ARG_VISIBILITY, null); if (visibility == null && statusReply != null) { visibility = getVisibility(statusReply.visibility); - } else if (visibility == null && currentAccount != null && currentAccount.mastodon_account.source != null) { + } else if (visibility == null && currentAccount != null && currentAccount.mastodon_account != null && currentAccount.mastodon_account.source != null) { visibility = currentAccount.mastodon_account.source.privacy; } mentionBooster = (app.fedilab.android.client.entities.api.Account) b.getSerializable(Helper.ARG_MENTION_BOOSTER); @@ -615,7 +615,7 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana //We change order for mentions //At first place the account that has been mentioned if it's not our statusDraftList.get(0).mentions = new ArrayList<>(); - if (statusReply.account.acct != null && !statusReply.account.acct.equalsIgnoreCase(currentAccount.mastodon_account.acct)) { + if (statusReply.account.acct != null && currentAccount.mastodon_account != null && !statusReply.account.acct.equalsIgnoreCase(currentAccount.mastodon_account.acct)) { Mention mention = new Mention(); mention.acct = "@" + statusReply.account.acct; mention.url = statusReply.account.url; @@ -626,7 +626,7 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana //There are other mentions to if (statusReply.mentions != null && statusReply.mentions.size() > 0) { for (Mention mentionTmp : statusReply.mentions) { - if (statusReply.account.acct != null && !mentionTmp.acct.equalsIgnoreCase(statusReply.account.acct) && !mentionTmp.acct.equalsIgnoreCase(currentAccount.mastodon_account.acct)) { + if (statusReply.account.acct != null && !mentionTmp.acct.equalsIgnoreCase(statusReply.account.acct) && currentAccount.mastodon_account != null && !mentionTmp.acct.equalsIgnoreCase(currentAccount.mastodon_account.acct)) { statusDraftList.get(0).mentions.add(mentionTmp); } } diff --git a/app/src/main/java/app/fedilab/android/activities/MastodonListActivity.java b/app/src/main/java/app/fedilab/android/activities/MastodonListActivity.java index 3d8a431c..a12da704 100644 --- a/app/src/main/java/app/fedilab/android/activities/MastodonListActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/MastodonListActivity.java @@ -277,7 +277,7 @@ public class MastodonListActivity extends BaseActivity implements MastodonListAd if (mastodonListList == null) { mastodonListList = new ArrayList<>(); } - if (newMastodonList != null) { + if (newMastodonList != null && mastodonListAdapter != null) { mastodonListList.add(0, newMastodonList); mastodonListAdapter.notifyItemInserted(0); } else { diff --git a/app/src/main/java/app/fedilab/android/activities/ProfileActivity.java b/app/src/main/java/app/fedilab/android/activities/ProfileActivity.java index 569016b3..38433773 100644 --- a/app/src/main/java/app/fedilab/android/activities/ProfileActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/ProfileActivity.java @@ -663,7 +663,10 @@ public class ProfileActivity extends BaseActivity { @Override public boolean onOptionsItemSelected(MenuItem item) { int itemId = item.getItemId(); - String[] splitAcct = account.acct.split("@"); + String[] splitAcct = null; + if (account.acct != null) { + splitAcct = account.acct.split("@"); + } SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(ProfileActivity.this); AlertDialog.Builder builderInner = null; final boolean isOwner = account.id != null && BaseMainActivity.currentUserID != null && account.id.compareToIgnoreCase(BaseMainActivity.currentUserID) == 0; @@ -677,7 +680,7 @@ public class ProfileActivity extends BaseActivity { if (itemId == android.R.id.home) { finish(); return true; - } else if (itemId == R.id.action_follow_instance) { + } else if (itemId == R.id.action_follow_instance && splitAcct != null) { String finalInstanceName = splitAcct[1]; ReorderVM reorderVM = new ViewModelProvider(ProfileActivity.this).get(ReorderVM.class); //Get pinned instances diff --git a/app/src/main/java/app/fedilab/android/client/entities/app/DomainsBlock.java b/app/src/main/java/app/fedilab/android/client/entities/app/DomainsBlock.java index 6843b11f..d72744a3 100644 --- a/app/src/main/java/app/fedilab/android/client/entities/app/DomainsBlock.java +++ b/app/src/main/java/app/fedilab/android/client/entities/app/DomainsBlock.java @@ -59,7 +59,12 @@ public class DomainsBlock { List domains = new ArrayList<>(); while ((line = br.readLine()) != null) { if (line.startsWith("0.0.0.0 ")) { - domains.add(line.replace("0.0.0.0 ", "").trim()); + try { + domains.add(line.replace("0.0.0.0 ", "").trim()); + } catch (Exception e) { + return; + } + } } br.close(); diff --git a/app/src/main/java/app/fedilab/android/helper/CustomEmoji.java b/app/src/main/java/app/fedilab/android/helper/CustomEmoji.java index 8f816ccc..51ce2fc8 100644 --- a/app/src/main/java/app/fedilab/android/helper/CustomEmoji.java +++ b/app/src/main/java/app/fedilab/android/helper/CustomEmoji.java @@ -95,7 +95,9 @@ public class CustomEmoji extends ReplacementSpan { ((Animatable) resource).start(); } imageDrawable = resource; - view.invalidate(); + if (view != null) { + view.invalidate(); + } } @Override diff --git a/app/src/main/java/app/fedilab/android/helper/Helper.java b/app/src/main/java/app/fedilab/android/helper/Helper.java index 8a675be5..2f3711b7 100644 --- a/app/src/main/java/app/fedilab/android/helper/Helper.java +++ b/app/src/main/java/app/fedilab/android/helper/Helper.java @@ -990,8 +990,12 @@ public class Helper { */ public static String getFileName(Context context, Uri uri) { ContentResolver resolver = context.getContentResolver(); - Cursor returnCursor = - resolver.query(uri, null, null, null, null); + Cursor returnCursor = null; + try { + returnCursor = + resolver.query(uri, null, null, null, null); + } catch (Exception ignored) { + } if (returnCursor != null) { try { int nameIndex = returnCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME); @@ -1092,7 +1096,7 @@ public class Helper { SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); boolean disableGif = sharedpreferences.getBoolean(context.getString(R.string.SET_DISABLE_GIF), false); String targetedUrl = disableGif ? account.mastodon_account.avatar_static : account.mastodon_account.avatar; - if (targetedUrl != null) { + if (targetedUrl != null && Helper.isValidContextForGlide(view.getContext())) { if (disableGif || (!targetedUrl.endsWith(".gif"))) { RequestBuilder requestBuilder = Glide.with(view.getContext()) .asDrawable() @@ -1112,7 +1116,7 @@ public class Helper { } requestBuilder.apply(new RequestOptions().transform(new CenterCrop(), new RoundedCorners(10))).into(view); } - } else { + } else if (Helper.isValidContextForGlide(view.getContext())) { Glide.with(view.getContext()) .asDrawable() .load(R.drawable.ic_person) @@ -1201,7 +1205,7 @@ public class Helper { int w = options.outWidth; int h = options.outHeight; - float valx = (float) 1.0 - (float) width / (float) w; + float valx = (float) 1.0 - width / (float) w; if (valx < 0) valx = 0; float valy = (h - Helper.convertDpToPixel(textSize, context) - 10) / (float) h; diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java index 7169469b..b13ccdc1 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java @@ -488,7 +488,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. } }); //For first tab we fetch new messages, if we keep position - if (slug.compareTo(Helper.getSlugOfFirstFragment(requireActivity(), currentUserID, currentInstance)) == 0 && rememberPosition) { + if (slug != null && slug.compareTo(Helper.getSlugOfFirstFragment(requireActivity(), currentUserID, currentInstance)) == 0 && rememberPosition) { route(DIRECTION.FETCH_NEW, true); } } diff --git a/app/src/main/java/app/fedilab/android/viewmodel/mastodon/NodeInfoVM.java b/app/src/main/java/app/fedilab/android/viewmodel/mastodon/NodeInfoVM.java index 522ccf54..a9af9fa8 100644 --- a/app/src/main/java/app/fedilab/android/viewmodel/mastodon/NodeInfoVM.java +++ b/app/src/main/java/app/fedilab/android/viewmodel/mastodon/NodeInfoVM.java @@ -66,39 +66,42 @@ public class NodeInfoVM extends AndroidViewModel { * @return LiveData */ public LiveData getNodeInfo(String instance) { - NodeInfoService nodeInfoService = init(instance); - nodeInfoMutableLiveData = new MutableLiveData<>(); - new Thread(() -> { - WellKnownNodeinfo.NodeInfo nodeInfo = null; + if (instance != null) { + NodeInfoService nodeInfoService = init(instance); + nodeInfoMutableLiveData = new MutableLiveData<>(); + new Thread(() -> { + WellKnownNodeinfo.NodeInfo nodeInfo = null; - Call nodeInfoLinksCall = nodeInfoService.getWellKnownNodeinfoLinks(); - if (nodeInfoLinksCall != null) { - try { - Response nodeInfoLinksResponse = nodeInfoLinksCall.execute(); - if (nodeInfoLinksResponse.isSuccessful() && nodeInfoLinksResponse.body() != null) { - WellKnownNodeinfo wellKnownNodeinfo = nodeInfoLinksResponse.body(); - Call wellKnownNodeinfoCall = nodeInfoService.getNodeinfo(wellKnownNodeinfo.links.get(0).href); - if (wellKnownNodeinfoCall != null) { - try { - Response response = wellKnownNodeinfoCall.execute(); - if (response.isSuccessful() && response.body() != null) { - nodeInfo = response.body(); + Call nodeInfoLinksCall = nodeInfoService.getWellKnownNodeinfoLinks(); + if (nodeInfoLinksCall != null) { + try { + Response nodeInfoLinksResponse = nodeInfoLinksCall.execute(); + if (nodeInfoLinksResponse.isSuccessful() && nodeInfoLinksResponse.body() != null) { + WellKnownNodeinfo wellKnownNodeinfo = nodeInfoLinksResponse.body(); + Call wellKnownNodeinfoCall = nodeInfoService.getNodeinfo(wellKnownNodeinfo.links.get(0).href); + if (wellKnownNodeinfoCall != null) { + try { + Response response = wellKnownNodeinfoCall.execute(); + if (response.isSuccessful() && response.body() != null) { + nodeInfo = response.body(); + } + } catch (Exception e) { + e.printStackTrace(); } - } catch (Exception e) { - e.printStackTrace(); } } + } catch (Exception e) { + e.printStackTrace(); } - } catch (Exception e) { - e.printStackTrace(); } - } - - Handler mainHandler = new Handler(Looper.getMainLooper()); - WellKnownNodeinfo.NodeInfo finalNodeInfo = nodeInfo; - Runnable myRunnable = () -> nodeInfoMutableLiveData.setValue(finalNodeInfo); - mainHandler.post(myRunnable); - }).start(); + Handler mainHandler = new Handler(Looper.getMainLooper()); + WellKnownNodeinfo.NodeInfo finalNodeInfo = nodeInfo; + Runnable myRunnable = () -> nodeInfoMutableLiveData.setValue(finalNodeInfo); + mainHandler.post(myRunnable); + }).start(); + } else { + nodeInfoMutableLiveData.setValue(null); + } return nodeInfoMutableLiveData; }