diff --git a/app/src/main/java/app/fedilab/android/BaseMainActivity.java b/app/src/main/java/app/fedilab/android/BaseMainActivity.java index 27fae89b..94c6ad25 100644 --- a/app/src/main/java/app/fedilab/android/BaseMainActivity.java +++ b/app/src/main/java/app/fedilab/android/BaseMainActivity.java @@ -487,7 +487,13 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt if (itemId == R.id.action_logout_account) { AlertDialog.Builder alt_bld = new AlertDialog.Builder(BaseMainActivity.this, Helper.dialogStyle()); alt_bld.setTitle(R.string.action_logout); - alt_bld.setMessage(getString(R.string.logout_account_confirmation, account.mastodon_account.username, account.instance)); + if (account.mastodon_account != null && account.mastodon_account.username != null && account.instance != null) { + alt_bld.setMessage(getString(R.string.logout_account_confirmation, account.mastodon_account.username, account.instance)); + } else if (account.mastodon_account != null && account.mastodon_account.acct != null) { + alt_bld.setMessage(getString(R.string.logout_account_confirmation, account.mastodon_account.acct, "")); + } else { + alt_bld.setMessage(getString(R.string.logout_account_confirmation, "", "")); + } alt_bld.setPositiveButton(R.string.action_logout, (dialog, id) -> { dialog.dismiss(); try { diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java index d27904f1..fae78c54 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java @@ -392,9 +392,11 @@ public class StatusAdapter extends RecyclerView.Adapter Status fetchedStatus = statusList.get(0); statusesVM.bookmark(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, fetchedStatus.id) .observe((LifecycleOwner) context, _status -> { - statusToDeal.bookmarked = _status.bookmarked; - sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null); - adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal)); + if (_status != null) { + statusToDeal.bookmarked = _status.bookmarked; + sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null); + adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal)); + } }); } else { Toasty.info(context, context.getString(R.string.toast_error_search), Toasty.LENGTH_SHORT).show(); @@ -404,17 +406,21 @@ public class StatusAdapter extends RecyclerView.Adapter if (statusToDeal.bookmarked) { statusesVM.unBookmark(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.id) .observe((LifecycleOwner) context, _status -> { - statusToDeal.bookmarked = _status.bookmarked; - sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null); - adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal)); + if (_status != null) { + statusToDeal.bookmarked = _status.bookmarked; + sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null); + adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal)); + } }); } else { ((SparkButton) v).playAnimation(); statusesVM.bookmark(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.id) .observe((LifecycleOwner) context, _status -> { - statusToDeal.bookmarked = _status.bookmarked; - sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null); - adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal)); + if (_status != null) { + statusToDeal.bookmarked = _status.bookmarked; + sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null); + adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal)); + } }); } } @@ -505,10 +511,12 @@ public class StatusAdapter extends RecyclerView.Adapter Status fetchedStatus = results.statuses.get(0); statusesVM.reblog(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, fetchedStatus.id, null) .observe((LifecycleOwner) context, _status -> { - statusToDeal.reblogged = _status.reblogged; - statusToDeal.reblogs_count = _status.reblogs_count; - sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null); - adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal)); + if (_status != null) { + statusToDeal.reblogged = _status.reblogged; + statusToDeal.reblogs_count = _status.reblogs_count; + sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null); + adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal)); + } }); } else { Toasty.info(context, context.getString(R.string.toast_error_search), Toasty.LENGTH_SHORT).show(); @@ -518,19 +526,23 @@ public class StatusAdapter extends RecyclerView.Adapter if (statusToDeal.reblogged) { statusesVM.unReblog(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.id) .observe((LifecycleOwner) context, _status -> { - statusToDeal.reblogged = _status.reblogged; - statusToDeal.reblogs_count = _status.reblogs_count; - sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null); - adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal)); + if (_status != null) { + statusToDeal.reblogged = _status.reblogged; + statusToDeal.reblogs_count = _status.reblogs_count; + sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null); + adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal)); + } }); } else { ((SparkButton) v).playAnimation(); statusesVM.reblog(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.id, null) .observe((LifecycleOwner) context, _status -> { - statusToDeal.reblogged = _status.reblogged; - statusToDeal.reblogs_count = _status.reblogs_count; - sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null); - adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal)); + if (_status != null) { + statusToDeal.reblogged = _status.reblogged; + statusToDeal.reblogs_count = _status.reblogs_count; + sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null); + adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal)); + } }); } } @@ -548,10 +560,12 @@ public class StatusAdapter extends RecyclerView.Adapter Status fetchedStatus = results.statuses.get(0); statusesVM.reblog(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, fetchedStatus.id, null) .observe((LifecycleOwner) context, _status -> { - statusToDeal.reblogged = _status.reblogged; - statusToDeal.reblogs_count = _status.reblogs_count; - sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null); - adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal)); + if (_status != null) { + statusToDeal.reblogged = _status.reblogged; + statusToDeal.reblogs_count = _status.reblogs_count; + sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null); + adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal)); + } }); } else { Toasty.info(context, context.getString(R.string.toast_error_search), Toasty.LENGTH_SHORT).show(); @@ -561,19 +575,23 @@ public class StatusAdapter extends RecyclerView.Adapter if (statusToDeal.reblogged) { statusesVM.unReblog(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.id) .observe((LifecycleOwner) context, _status -> { - statusToDeal.reblogged = _status.reblogged; - statusToDeal.reblogs_count = _status.reblogs_count; - sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null); - adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal)); + if (_status != null) { + statusToDeal.reblogged = _status.reblogged; + statusToDeal.reblogs_count = _status.reblogs_count; + sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null); + adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal)); + } }); } else { ((SparkButton) v).playAnimation(); statusesVM.reblog(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.id, null) .observe((LifecycleOwner) context, _status -> { - statusToDeal.reblogged = _status.reblogged; - statusToDeal.reblogs_count = _status.reblogs_count; - sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null); - adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal)); + if (_status != null) { + statusToDeal.reblogged = _status.reblogged; + statusToDeal.reblogs_count = _status.reblogs_count; + sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null); + adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal)); + } }); } } @@ -605,10 +623,12 @@ public class StatusAdapter extends RecyclerView.Adapter Status fetchedStatus = results.statuses.get(0); statusesVM.favourite(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, fetchedStatus.id) .observe((LifecycleOwner) context, _status -> { - statusToDeal.favourited = _status.favourited; - statusToDeal.favourites_count = _status.favourites_count; - sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null); - adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal)); + if (_status != null) { + statusToDeal.favourited = _status.favourited; + statusToDeal.favourites_count = _status.favourites_count; + sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null); + adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal)); + } }); } else { Toasty.info(context, context.getString(R.string.toast_error_search), Toasty.LENGTH_SHORT).show(); @@ -618,18 +638,22 @@ public class StatusAdapter extends RecyclerView.Adapter if (status.favourited) { statusesVM.unFavourite(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.id) .observe((LifecycleOwner) context, _status -> { - statusToDeal.favourited = _status.favourited; - statusToDeal.favourites_count = _status.favourites_count; - adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal)); + if (_status != null) { + statusToDeal.favourited = _status.favourited; + statusToDeal.favourites_count = _status.favourites_count; + adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal)); + } }); } else { ((SparkButton) v).playAnimation(); statusesVM.favourite(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.id) .observe((LifecycleOwner) context, _status -> { - statusToDeal.favourited = _status.favourited; - statusToDeal.favourites_count = _status.favourites_count; - sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null); - adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal)); + if (_status != null) { + statusToDeal.favourited = _status.favourited; + statusToDeal.favourites_count = _status.favourites_count; + sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null); + adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal)); + } }); } } @@ -647,10 +671,12 @@ public class StatusAdapter extends RecyclerView.Adapter Status fetchedStatus = results.statuses.get(0); statusesVM.favourite(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, fetchedStatus.id) .observe((LifecycleOwner) context, _status -> { - statusToDeal.favourited = _status.favourited; - statusToDeal.favourites_count = _status.favourites_count; - sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null); - adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal)); + if (_status != null) { + statusToDeal.favourited = _status.favourited; + statusToDeal.favourites_count = _status.favourites_count; + sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null); + adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal)); + } }); } else { Toasty.info(context, context.getString(R.string.toast_error_search), Toasty.LENGTH_SHORT).show(); @@ -660,18 +686,22 @@ public class StatusAdapter extends RecyclerView.Adapter if (statusToDeal.favourited) { statusesVM.unFavourite(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.id) .observe((LifecycleOwner) context, _status -> { - statusToDeal.favourited = _status.favourited; - statusToDeal.favourites_count = _status.favourites_count; - adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal)); + if (_status != null) { + statusToDeal.favourited = _status.favourited; + statusToDeal.favourites_count = _status.favourites_count; + adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal)); + } }); } else { ((SparkButton) v).playAnimation(); statusesVM.favourite(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.id) .observe((LifecycleOwner) context, _status -> { - statusToDeal.favourited = _status.favourited; - statusToDeal.favourites_count = _status.favourites_count; - sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null); - adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal)); + if (_status != null) { + statusToDeal.favourited = _status.favourited; + statusToDeal.favourites_count = _status.favourites_count; + sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null); + adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal)); + } }); } } diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/login/FragmentLoginMain.java b/app/src/main/java/app/fedilab/android/ui/fragment/login/FragmentLoginMain.java index f8e54f0c..1afde0aa 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/login/FragmentLoginMain.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/login/FragmentLoginMain.java @@ -250,37 +250,35 @@ public class FragmentLoginMain extends Fragment { } catch (UnsupportedEncodingException e) { Toasty.error(requireActivity(), getString(R.string.client_error), Toast.LENGTH_LONG).show(); } - if (api == Account.API.MASTODON) { - String scopes = ((LoginActivity) requireActivity()).requestedAdmin() ? Helper.OAUTH_SCOPES_ADMIN : Helper.OAUTH_SCOPES; - AppsVM appsVM = new ViewModelProvider(requireActivity()).get(AppsVM.class); - appsVM.createApp(currentInstance, getString(R.string.app_name), - Helper.REDIRECT_CONTENT_WEB, - scopes, - Helper.WEBSITE_VALUE - ).observe(requireActivity(), app -> { - client_id = app.client_id; - client_secret = app.client_secret; - String redirectUrl = MastodonHelper.authorizeURL(currentInstance, client_id, ((LoginActivity) requireActivity()).requestedAdmin()); - SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity()); - boolean embedded_browser = sharedpreferences.getBoolean(getString(R.string.SET_EMBEDDED_BROWSER), true); - if (embedded_browser) { - Intent i = new Intent(requireActivity(), WebviewConnectActivity.class); - i.putExtra("login_url", redirectUrl); - i.putExtra("requestedAdmin", ((LoginActivity) requireActivity()).requestedAdmin()); - startActivity(i); - requireActivity().finish(); - } else { - Intent intent = new Intent(Intent.ACTION_VIEW); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - intent.setData(Uri.parse(redirectUrl)); - try { - startActivity(intent); - } catch (Exception e) { - Toasty.error(requireActivity(), getString(R.string.toast_error), Toast.LENGTH_LONG).show(); - } - + String scopes = ((LoginActivity) requireActivity()).requestedAdmin() ? Helper.OAUTH_SCOPES_ADMIN : Helper.OAUTH_SCOPES; + AppsVM appsVM = new ViewModelProvider(requireActivity()).get(AppsVM.class); + appsVM.createApp(currentInstance, getString(R.string.app_name), + Helper.REDIRECT_CONTENT_WEB, + scopes, + Helper.WEBSITE_VALUE + ).observe(requireActivity(), app -> { + client_id = app.client_id; + client_secret = app.client_secret; + String redirectUrl = MastodonHelper.authorizeURL(currentInstance, client_id, ((LoginActivity) requireActivity()).requestedAdmin()); + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity()); + boolean embedded_browser = sharedpreferences.getBoolean(getString(R.string.SET_EMBEDDED_BROWSER), true); + if (embedded_browser) { + Intent i = new Intent(requireActivity(), WebviewConnectActivity.class); + i.putExtra("login_url", redirectUrl); + i.putExtra("requestedAdmin", ((LoginActivity) requireActivity()).requestedAdmin()); + startActivity(i); + requireActivity().finish(); + } else { + Intent intent = new Intent(Intent.ACTION_VIEW); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + intent.setData(Uri.parse(redirectUrl)); + try { + startActivity(intent); + } catch (Exception e) { + Toasty.error(requireActivity(), getString(R.string.toast_error), Toast.LENGTH_LONG).show(); } - }); - } + + } + }); } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_conversation.xml b/app/src/main/res/layout/activity_conversation.xml index 7713c258..762d1a37 100644 --- a/app/src/main/res/layout/activity_conversation.xml +++ b/app/src/main/res/layout/activity_conversation.xml @@ -57,13 +57,12 @@ - + app:defaultNavHost="true" /> \ No newline at end of file