Fix crashes from bug reports.

This commit is contained in:
Thomas 2022-11-23 10:52:09 +01:00
parent a389681b86
commit 0e0fb6e13c
5 changed files with 46 additions and 17 deletions

View File

@ -586,7 +586,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
}
Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> {
if (currentAccount == null) {
if (currentAccount == null || currentAccount.mastodon_account == null) {
//It is not, the user is redirected to the login page
Intent myIntent = new Intent(BaseMainActivity.this, LoginActivity.class);
startActivity(myIntent);
@ -701,16 +701,18 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
new ViewModelProvider(BaseMainActivity.this).get(AccountsVM.class).getConnectedAccount(currentInstance, currentToken)
.observe(BaseMainActivity.this, mastodonAccount -> {
//Initialize static var
currentAccount.mastodon_account = mastodonAccount;
displayReleaseNotesIfNeeded(BaseMainActivity.this, false);
new Thread(() -> {
try {
//Update account in db
new Account(BaseMainActivity.this).insertOrUpdate(currentAccount);
} catch (DBException e) {
e.printStackTrace();
}
}).start();
if (mastodonAccount != null) {
currentAccount.mastodon_account = mastodonAccount;
displayReleaseNotesIfNeeded(BaseMainActivity.this, false);
new Thread(() -> {
try {
//Update account in db
new Account(BaseMainActivity.this).insertOrUpdate(currentAccount);
} catch (DBException e) {
e.printStackTrace();
}
}).start();
}
});
};
@ -1035,6 +1037,17 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
Matcher matcherLink = null;
matcherLink = link.matcher(url);
if (matcherLink.find()) {
if (currentAccount == null) {
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(BaseMainActivity.this);
if (currentToken == null || currentToken.trim().isEmpty()) {
currentToken = sharedpreferences.getString(Helper.PREF_USER_TOKEN, null);
}
try {
currentAccount = new Account(BaseMainActivity.this).getConnectedAccount();
} catch (DBException e) {
e.printStackTrace();
}
}
if (matcherLink.group(3) != null && Objects.requireNonNull(matcherLink.group(3)).length() > 0) { //It's a toot
CrossActionHelper.fetchRemoteStatus(BaseMainActivity.this, currentAccount, url, new CrossActionHelper.Callback() {
@Override

View File

@ -277,7 +277,11 @@ public class FilterActivity extends BaseActivity implements FilterAdapter.Delete
binding.addFilter.setOnClickListener(v -> addEditFilter(FilterActivity.this, null, filter -> {
if (filter != null) {
if (MainActivity.mainFilters == null) {
MainActivity.mainFilters = new ArrayList<>();
}
filterList.add(0, filter);
MainActivity.mainFilters.add(filter);
if (filterAdapter != null) {
filterAdapter.notifyItemInserted(0);
} else {

View File

@ -1029,7 +1029,7 @@ public class Helper {
final Activity activity = (Activity) context;
return !activity.isDestroyed() && !activity.isFinishing();
}
return true;
return false;
}
/**

View File

@ -78,14 +78,14 @@ public class FilterAdapter extends RecyclerView.Adapter<FilterAdapter.FilterView
contextString.append(ct).append(" ");
holder.binding.filterContext.setText(contextString.toString());
holder.binding.editFilter.setOnClickListener(v -> FilterActivity.addEditFilter(context, filter, filter1 -> {
if (filter1 != null) {
if (filter1 != null && BaseMainActivity.mainFilters.size() > position) {
BaseMainActivity.mainFilters.get(position).context = filter1.context;
BaseMainActivity.mainFilters.get(position).expires_at = filter1.expires_at;
BaseMainActivity.mainFilters.get(position).filter_action = filter1.filter_action;
BaseMainActivity.mainFilters.get(position).keywords = filter1.keywords;
BaseMainActivity.mainFilters.get(position).title = filter1.title;
filterAdapter.notifyItemChanged(position);
}
filterAdapter.notifyItemChanged(position);
}));
holder.binding.deleteFilter.setOnClickListener(v -> {
AlertDialog.Builder builder = new AlertDialog.Builder(context, Helper.dialogStyle());

View File

@ -1611,7 +1611,11 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
.observe((LifecycleOwner) context, poll -> {
int i = 0;
for (Poll.PollItem item : statusToDeal.poll.options) {
poll.options.get(i).span_title = item.span_title;
if (item.span_title != null) {
poll.options.get(i).span_title = item.span_title;
} else {
poll.options.get(i).span_title = new SpannableString(item.title);
}
i++;
}
statusToDeal.poll = poll;
@ -1627,7 +1631,11 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
if (poll != null) {
int i = 0;
for (Poll.PollItem item : statusToDeal.poll.options) {
poll.options.get(i).span_title = item.span_title;
if (item.span_title != null) {
poll.options.get(i).span_title = item.span_title;
} else {
poll.options.get(i).span_title = new SpannableString(item.title);
}
i++;
}
statusToDeal.poll = poll;
@ -1642,7 +1650,11 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
//Store span elements
int i = 0;
for (Poll.PollItem item : statusToDeal.poll.options) {
poll.options.get(i).span_title = item.span_title;
if (item.span_title != null) {
poll.options.get(i).span_title = item.span_title;
} else {
poll.options.get(i).span_title = new SpannableString(item.title);
}
i++;
}
statusToDeal.poll = poll;