mirror of
https://codeberg.org/tom79/Fedilab.git
synced 2024-12-22 16:50:04 +02:00
Some bug fixes + login issue
This commit is contained in:
parent
0ee936f52d
commit
4792c4971c
4 changed files with 123 additions and 90 deletions
|
@ -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 {
|
||||
|
|
|
@ -392,9 +392,11 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|||
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<RecyclerView.ViewHolder>
|
|||
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<RecyclerView.ViewHolder>
|
|||
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<RecyclerView.ViewHolder>
|
|||
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<RecyclerView.ViewHolder>
|
|||
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<RecyclerView.ViewHolder>
|
|||
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<RecyclerView.ViewHolder>
|
|||
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<RecyclerView.ViewHolder>
|
|||
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<RecyclerView.ViewHolder>
|
|||
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<RecyclerView.ViewHolder>
|
|||
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));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -57,13 +57,12 @@
|
|||
</androidx.appcompat.widget.Toolbar>
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
<fragment
|
||||
<androidx.fragment.app.FragmentContainerView
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
android:id="@+id/nav_host_fragment_content_main"
|
||||
android:name="androidx.navigation.fragment.NavHostFragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:defaultNavHost="true"
|
||||
/>
|
||||
app:defaultNavHost="true" />
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
</androidx.drawerlayout.widget.DrawerLayout>
|
Loading…
Reference in a new issue