Fix some crashes

This commit is contained in:
Thomas 2022-11-05 14:57:41 +01:00
parent c2a08c6df8
commit 92157dc8dc
4 changed files with 42 additions and 34 deletions

View file

@ -665,12 +665,12 @@ public class ProfileActivity extends BaseActivity {
public boolean onOptionsItemSelected(MenuItem item) {
int itemId = item.getItemId();
String[] splitAcct = null;
if (account.acct != null) {
if (account != null && 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;
final boolean isOwner = account != null && account.id != null && BaseMainActivity.currentUserID != null && account.id.compareToIgnoreCase(BaseMainActivity.currentUserID) == 0;
final String[] stringArrayConf;
if (isOwner) {
stringArrayConf = getResources().getStringArray(R.array.more_action_owner_confirm);

View file

@ -82,6 +82,7 @@ public class NotificationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
@Override
public int getItemViewType(int position) {
String type = notificationList.get(position).type;
if (type != null) {
switch (type) {
case "follow":
return TYPE_FOLLOW;
@ -100,6 +101,7 @@ public class NotificationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
case "pleroma:emoji_reaction":
return TYPE_REACTION;
}
}
return super.getItemViewType(position);
}
@ -279,7 +281,7 @@ public class NotificationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
holderStatus.bindingNotification.containerTransparent.setVisibility(View.VISIBLE);
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
boolean displayMedia = sharedpreferences.getBoolean(context.getString(R.string.SET_DISPLAY_MEDIA_NOTIFICATION), true);
if (displayMedia && notification.status.media_attachments != null && notification.status.media_attachments.size() > 0) {
if (displayMedia && notification.status != null && notification.status.media_attachments != null && notification.status.media_attachments.size() > 0) {
holderStatus.bindingNotification.status.mediaContainer.setVisibility(View.VISIBLE);
} else {
holderStatus.bindingNotification.status.mediaContainer.setVisibility(View.GONE);

View file

@ -691,7 +691,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show();
searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.uri, null, "statuses", false, true, false, 0, null, null, 1)
.observe((LifecycleOwner) context, results -> {
if (results.statuses != null && results.statuses.size() > 0) {
if (results != null && results.statuses != null && results.statuses.size() > 0) {
Status fetchedStatus = statusList.get(0);
statusesVM.bookmark(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, fetchedStatus.id)
.observe((LifecycleOwner) context, _status -> manageAction(context, adapter, holder, CrossActionHelper.TypeOfCrossAction.BOOKMARK_ACTION, statusToDeal, _status, true));
@ -716,7 +716,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show();
searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.uri, null, "statuses", false, true, false, 0, null, null, 1)
.observe((LifecycleOwner) context, results -> {
if (results.statuses != null && results.statuses.size() > 0) {
if (results != null && results.statuses != null && results.statuses.size() > 0) {
Status fetchedStatus = results.statuses.get(0);
Intent intent = new Intent(context, ProfileActivity.class);
Bundle b = new Bundle();
@ -746,7 +746,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show();
searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.uri, null, "statuses", false, true, false, 0, null, null, 1)
.observe((LifecycleOwner) context, results -> {
if (results.statuses != null && results.statuses.size() > 0) {
if (results != null && results.statuses != null && results.statuses.size() > 0) {
Status fetchedStatus = results.statuses.get(0);
Intent intent = new Intent(context, ProfileActivity.class);
Bundle b = new Bundle();
@ -792,7 +792,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show();
searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.uri, null, "statuses", false, true, false, 0, null, null, 1)
.observe((LifecycleOwner) context, results -> {
if (results.statuses != null && results.statuses.size() > 0) {
if (results != null && results.statuses != null && results.statuses.size() > 0) {
Status fetchedStatus = results.statuses.get(0);
statusesVM.reblog(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, fetchedStatus.id, null)
.observe((LifecycleOwner) context, _status -> manageAction(context, adapter, holder, CrossActionHelper.TypeOfCrossAction.REBLOG_ACTION, statusToDeal, _status, true));
@ -820,7 +820,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show();
searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.uri, null, "statuses", false, true, false, 0, null, null, 1)
.observe((LifecycleOwner) context, results -> {
if (results.statuses != null && results.statuses.size() > 0) {
if (results != null && results.statuses != null && results.statuses.size() > 0) {
Status fetchedStatus = results.statuses.get(0);
statusesVM.reblog(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, fetchedStatus.id, null)
.observe((LifecycleOwner) context, _status -> manageAction(context, adapter, holder, CrossActionHelper.TypeOfCrossAction.REBLOG_ACTION, statusToDeal, _status, true));
@ -862,7 +862,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show();
searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.uri, null, "statuses", false, true, false, 0, null, null, 1)
.observe((LifecycleOwner) context, results -> {
if (results.statuses != null && results.statuses.size() > 0) {
if (results != null && results.statuses != null && results.statuses.size() > 0) {
Status fetchedStatus = results.statuses.get(0);
statusesVM.favourite(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, fetchedStatus.id)
.observe((LifecycleOwner) context, _status -> manageAction(context, adapter, holder, CrossActionHelper.TypeOfCrossAction.FAVOURITE_ACTION, statusToDeal, _status, true));
@ -890,7 +890,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show();
searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.uri, null, "statuses", false, true, false, 0, null, null, 1)
.observe((LifecycleOwner) context, results -> {
if (results.statuses != null && results.statuses.size() > 0) {
if (results != null && results.statuses != null && results.statuses.size() > 0) {
Status fetchedStatus = results.statuses.get(0);
statusesVM.favourite(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, fetchedStatus.id)
.observe((LifecycleOwner) context, _status -> manageAction(context, adapter, holder, CrossActionHelper.TypeOfCrossAction.FAVOURITE_ACTION, statusToDeal, _status, true));
@ -1395,7 +1395,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show();
searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.uri, null, "statuses", false, true, false, 0, null, null, 1)
.observe((LifecycleOwner) context, results -> {
if (results.statuses != null && results.statuses.size() > 0) {
if (results != null && results.statuses != null && results.statuses.size() > 0) {
Status fetchedStatus = results.statuses.get(0);
if (fetchedStatus.reblogs_count > 0) {
Intent intent = new Intent(context, StatusInfoActivity.class);
@ -1422,7 +1422,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show();
searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.uri, null, "statuses", false, true, false, 0, null, null, 1)
.observe((LifecycleOwner) context, results -> {
if (results.statuses != null && results.statuses.size() > 0) {
if (results != null && results.statuses != null && results.statuses.size() > 0) {
Status fetchedStatus = results.statuses.get(0);
if (fetchedStatus.favourites_count > 0) {
Intent intent = new Intent(context, StatusInfoActivity.class);
@ -1564,7 +1564,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show();
searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.uri, null, "statuses", false, true, false, 0, null, null, 1)
.observe((LifecycleOwner) context, results -> {
if (results.statuses != null && results.statuses.size() > 0) {
if (results != null && results.statuses != null && results.statuses.size() > 0) {
Status fetchedStatus = results.statuses.get(0);
statusesVM.votePoll(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, fetchedStatus.poll.id, choice)
.observe((LifecycleOwner) context, poll -> {
@ -1646,7 +1646,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show();
searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.uri, null, "statuses", false, true, false, 0, null, null, 1)
.observe((LifecycleOwner) context, results -> {
if (results.statuses != null && results.statuses.size() > 0) {
if (results != null && results.statuses != null && results.statuses.size() > 0) {
Status fetchedStatus = results.statuses.get(0);
Intent intent = new Intent(context, ContextActivity.class);
intent.putExtra(Helper.ARG_STATUS, fetchedStatus);
@ -1971,7 +1971,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
Toasty.info(context, context.getString(R.string.retrieve_remote_status), Toasty.LENGTH_SHORT).show();
searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.uri, null, "statuses", false, true, false, 0, null, null, 1)
.observe((LifecycleOwner) context, results -> {
if (results.statuses != null && results.statuses.size() > 0) {
if (results != null && results.statuses != null && results.statuses.size() > 0) {
Status fetchedStatus = statusList.get(0);
Intent intent = new Intent(context, ComposeActivity.class);
intent.putExtra(Helper.ARG_STATUS_REPLY, fetchedStatus);

View file

@ -66,9 +66,15 @@ public class NodeInfoVM extends AndroidViewModel {
* @return LiveData<WellKnownNodeinfo.NodeInfo>
*/
public LiveData<WellKnownNodeinfo.NodeInfo> getNodeInfo(String instance) {
if (instance != null) {
NodeInfoService nodeInfoService = init(instance);
nodeInfoMutableLiveData = new MutableLiveData<>();
if (instance != null) {
NodeInfoService nodeInfoService;
try {
nodeInfoService = init(instance);
} catch (Exception e) {
nodeInfoMutableLiveData.setValue(null);
return nodeInfoMutableLiveData;
}
new Thread(() -> {
WellKnownNodeinfo.NodeInfo nodeInfo = null;