mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-22 14:47:29 +00:00
fix pending badge
This commit is contained in:
parent
ac89f9d70e
commit
aca44f0ab9
@ -5,6 +5,7 @@ import android.content.Context;
|
|||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
@ -104,6 +105,11 @@ public class DirectMessageInboxFragment extends Fragment implements SwipeRefresh
|
|||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
unregisterReceiver();
|
unregisterReceiver();
|
||||||
|
isPendingRequestTotalBadgeAttached = false;
|
||||||
|
if (pendingRequestTotalBadgeDrawable != null) {
|
||||||
|
BadgeUtils.detachBadgeDrawable(pendingRequestTotalBadgeDrawable, fragmentActivity.getToolbar(), pendingRequestsMenuItem.getItemId());
|
||||||
|
pendingRequestTotalBadgeDrawable = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -124,21 +130,13 @@ public class DirectMessageInboxFragment extends Fragment implements SwipeRefresh
|
|||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
unregisterReceiver();
|
unregisterReceiver();
|
||||||
isPendingRequestTotalBadgeAttached = false;
|
|
||||||
if (pendingRequestTotalBadgeDrawable != null) {
|
|
||||||
BadgeUtils.detachBadgeDrawable(pendingRequestTotalBadgeDrawable, fragmentActivity.getToolbar(), pendingRequestsMenuItem.getItemId());
|
|
||||||
pendingRequestTotalBadgeDrawable = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreateOptionsMenu(@NonNull final Menu menu, @NonNull final MenuInflater inflater) {
|
public void onCreateOptionsMenu(@NonNull final Menu menu, @NonNull final MenuInflater inflater) {
|
||||||
super.onCreateOptionsMenu(menu, inflater);
|
inflater.inflate(R.menu.dm_inbox_menu, menu);
|
||||||
pendingRequestsMenuItem = menu.add(Menu.NONE, R.id.pending_requests, Menu.NONE, "Pending requests");
|
pendingRequestsMenuItem = menu.findItem(R.id.pending_requests);
|
||||||
pendingRequestsMenuItem.setIcon(R.drawable.ic_account_clock_24)
|
pendingRequestsMenuItem.setVisible(isPendingRequestTotalBadgeAttached);
|
||||||
.setVisible(false)
|
|
||||||
.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS);
|
|
||||||
attachPendingRequestsBadge(viewModel.getPendingRequestsTotal().getValue());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -213,7 +211,16 @@ public class DirectMessageInboxFragment extends Fragment implements SwipeRefresh
|
|||||||
|
|
||||||
@SuppressLint("UnsafeExperimentalUsageError")
|
@SuppressLint("UnsafeExperimentalUsageError")
|
||||||
private void attachPendingRequestsBadge(@Nullable final Integer count) {
|
private void attachPendingRequestsBadge(@Nullable final Integer count) {
|
||||||
if (pendingRequestsMenuItem == null) return;
|
if (pendingRequestsMenuItem == null) {
|
||||||
|
final Handler handler = new Handler();
|
||||||
|
handler.postDelayed(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
attachPendingRequestsBadge(count);
|
||||||
|
}
|
||||||
|
}, 500);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (pendingRequestTotalBadgeDrawable == null) {
|
if (pendingRequestTotalBadgeDrawable == null) {
|
||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
if (context == null) return;
|
if (context == null) return;
|
||||||
|
10
app/src/main/res/menu/dm_inbox_menu.xml
Normal file
10
app/src/main/res/menu/dm_inbox_menu.xml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
<item
|
||||||
|
android:id="@+id/pending_requests"
|
||||||
|
android:icon="@drawable/ic_account_clock_24"
|
||||||
|
android:title="@string/pending_requests"
|
||||||
|
android:visible="false"
|
||||||
|
app:showAsAction="always" />
|
||||||
|
</menu>
|
@ -4,5 +4,4 @@
|
|||||||
<item name="unsend" type="id" />
|
<item name="unsend" type="id" />
|
||||||
<item name="forward" type="id" />
|
<item name="forward" type="id" />
|
||||||
<item name="detail" type="id" />
|
<item name="detail" type="id" />
|
||||||
<item name="pending_requests" type="id" />
|
|
||||||
</resources>
|
</resources>
|
Loading…
Reference in New Issue
Block a user