mirror of
https://codeberg.org/gitnex/GitNex.git
synced 2024-12-16 15:48:13 +08:00
Show notifications toast when switch accounts (#1124)
As title Co-authored-by: M M Arif <mmarif@swatian.com> Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1124 Reviewed-by: qwerty287 <qwerty287@noreply.codeberg.org>
This commit is contained in:
parent
7d271a236e
commit
b2196fdf87
@ -762,6 +762,7 @@ public class IssueDetailActivity extends BaseActivity implements LabelsListAdapt
|
||||
|
||||
if(issue.getIssue().getDueDate() != null) {
|
||||
|
||||
viewBinding.dueDateFrame.setVisibility(View.VISIBLE);
|
||||
if(timeFormat.equals("normal") || timeFormat.equals("pretty")) {
|
||||
|
||||
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd", locale);
|
||||
|
@ -5,6 +5,7 @@ import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Handler;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@ -14,9 +15,11 @@ import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.content.res.AppCompatResources;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import org.gitnex.tea4j.v2.models.NotificationCount;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.activities.AddNewAccountActivity;
|
||||
import org.mian.gitnex.clients.PicassoService;
|
||||
import org.mian.gitnex.clients.RetrofitClient;
|
||||
import org.mian.gitnex.database.api.BaseApi;
|
||||
import org.mian.gitnex.database.api.UserAccountsApi;
|
||||
import org.mian.gitnex.database.models.UserAccount;
|
||||
@ -27,6 +30,8 @@ import org.mian.gitnex.helpers.Toasty;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import io.mikael.urlbuilder.UrlBuilder;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
|
||||
/**
|
||||
* @author M M Arif
|
||||
@ -118,6 +123,7 @@ public class UserAccountsAdapter extends RecyclerView.Adapter<UserAccountsAdapte
|
||||
.toString();
|
||||
|
||||
Toasty.success(context, context.getResources().getString(R.string.switchAccountSuccess, userAccount.getUserName(), url));
|
||||
getNotificationsCount();
|
||||
((Activity) context).recreate();
|
||||
dialog.dismiss();
|
||||
|
||||
@ -142,6 +148,33 @@ public class UserAccountsAdapter extends RecyclerView.Adapter<UserAccountsAdapte
|
||||
Toasty.success(context, context.getResources().getString(R.string.accountDeletedMessage));
|
||||
}
|
||||
|
||||
private void getNotificationsCount() {
|
||||
|
||||
Call<NotificationCount> call = RetrofitClient.getApiInterface(context).notifyNewAvailable();
|
||||
|
||||
call.enqueue(new Callback<>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<NotificationCount> call, @NonNull retrofit2.Response<NotificationCount> response) {
|
||||
|
||||
NotificationCount notificationCount = response.body();
|
||||
|
||||
if(response.code() == 200) {
|
||||
|
||||
assert notificationCount != null;
|
||||
if(notificationCount.getNew() > 0) {
|
||||
String toastMsg = context.getResources().getQuantityString(R.plurals.youHaveNewNotifications, Math.toIntExact(notificationCount.getNew()), Math.toIntExact(notificationCount.getNew()));
|
||||
new Handler().postDelayed(() -> Toasty.info(context, toastMsg), 5000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<NotificationCount> call, @NonNull Throwable t) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public UserAccountsAdapter.UserAccountsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
|
@ -25,12 +25,12 @@ import java.util.List;
|
||||
import io.mikael.urlbuilder.UrlBuilder;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
* @author M M Arif
|
||||
*/
|
||||
|
||||
public class UserAccountsNavAdapter extends RecyclerView.Adapter<UserAccountsNavAdapter.UserAccountsViewHolder> {
|
||||
|
||||
private static DrawerLayout drawer;
|
||||
private final DrawerLayout drawer;
|
||||
private final List<UserAccount> userAccountsList;
|
||||
private final Context context;
|
||||
|
||||
@ -38,7 +38,7 @@ public class UserAccountsNavAdapter extends RecyclerView.Adapter<UserAccountsNav
|
||||
|
||||
this.context = ctx;
|
||||
this.userAccountsList = userAccountsListMain;
|
||||
drawer = drawerLayout;
|
||||
this.drawer = drawerLayout;
|
||||
}
|
||||
|
||||
class UserAccountsViewHolder extends RecyclerView.ViewHolder {
|
||||
@ -55,9 +55,7 @@ public class UserAccountsNavAdapter extends RecyclerView.Adapter<UserAccountsNav
|
||||
customDialogUserAccountsList();
|
||||
drawer.closeDrawers();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
@ -7,7 +7,7 @@ import com.google.android.material.snackbar.Snackbar;
|
||||
import org.mian.gitnex.R;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
* @author M M Arif
|
||||
*/
|
||||
|
||||
public class SnackBar {
|
||||
@ -16,7 +16,7 @@ public class SnackBar {
|
||||
Snackbar snackBar = Snackbar.make(view, message, Snackbar.LENGTH_LONG);
|
||||
View sbView = snackBar.getView();
|
||||
TextView textView = sbView.findViewById(R.id.snackbar_text);
|
||||
textView.setTextColor(context.getResources().getColor(R.color.colorWhite));
|
||||
textView.setTextColor(context.getColor(R.color.colorWhite));
|
||||
snackBar.show();
|
||||
}
|
||||
|
||||
@ -24,7 +24,7 @@ public class SnackBar {
|
||||
Snackbar snackBar = Snackbar.make(view, message, Snackbar.LENGTH_LONG);
|
||||
View sbView = snackBar.getView();
|
||||
TextView textView = sbView.findViewById(R.id.snackbar_text);
|
||||
textView.setTextColor(context.getResources().getColor(R.color.colorLightGreen));
|
||||
textView.setTextColor(context.getColor(R.color.colorLightGreen));
|
||||
snackBar.show();
|
||||
}
|
||||
|
||||
@ -32,7 +32,7 @@ public class SnackBar {
|
||||
Snackbar snackBar = Snackbar.make(view, message, Snackbar.LENGTH_LONG);
|
||||
View sbView = snackBar.getView();
|
||||
TextView textView = sbView.findViewById(R.id.snackbar_text);
|
||||
textView.setTextColor(context.getResources().getColor(R.color.lightYellow));
|
||||
textView.setTextColor(context.getColor(R.color.lightYellow));
|
||||
snackBar.show();
|
||||
}
|
||||
|
||||
@ -40,7 +40,7 @@ public class SnackBar {
|
||||
Snackbar snackBar = Snackbar.make(view, message, Snackbar.LENGTH_LONG);
|
||||
View sbView = snackBar.getView();
|
||||
TextView textView = sbView.findViewById(R.id.snackbar_text);
|
||||
textView.setTextColor(context.getResources().getColor(R.color.darkRed));
|
||||
textView.setTextColor(context.getColor(R.color.darkRed));
|
||||
snackBar.show();
|
||||
}
|
||||
}
|
||||
|
@ -127,6 +127,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="end|center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:visibility="gone"
|
||||
tools:ignore="UseCompoundDrawables">
|
||||
|
||||
<ImageView
|
||||
@ -152,6 +153,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="end|center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:visibility="gone"
|
||||
tools:ignore="UseCompoundDrawables">
|
||||
|
||||
<ImageView
|
||||
|
@ -653,6 +653,10 @@
|
||||
<string name="mainNotificationChannelName">Notifications</string>
|
||||
<string name="mainNotificationChannelDescription">This is the main notification channel of GitNex.</string>
|
||||
<string name="notificationExtraInfo" translatable="false">- %s (%s)</string>
|
||||
<plurals name="youHaveNewNotifications">
|
||||
<item quantity="one">You have %s new notification.</item>
|
||||
<item quantity="other">You have %s new notifications.</item>
|
||||
</plurals>
|
||||
|
||||
<string name="isRead">Read</string>
|
||||
<string name="isUnread">Unread</string>
|
||||
|
Loading…
Reference in New Issue
Block a user