mirror of
https://framagit.org/tom79/fedilab-tube
synced 2025-04-13 18:12:09 +02:00
Fix issue #160 - Add a notification counter
This commit is contained in:
parent
2e8a86fe20
commit
f168f101bc
@ -202,6 +202,7 @@ dependencies {
|
||||
implementation 'com.fasterxml.jackson.core:jackson-core:2.12.0'
|
||||
implementation 'org.slf4j:slf4j-simple:1.7.30'
|
||||
|
||||
|
||||
google_fullImplementation "com.android.billingclient:billing:3.0.2"
|
||||
|
||||
fdroid_peertube_apps_educImplementation 'org.matomo.sdk:tracker:4.1.2'
|
||||
|
@ -210,6 +210,7 @@ public class AccountActivity extends AppCompatActivity {
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == android.R.id.home) {
|
||||
finish();
|
||||
overridePendingTransition(R.anim.slide_out_up, R.anim.slide_in_up_down);
|
||||
return true;
|
||||
} else if (item.getItemId() == R.id.action_add_account) {
|
||||
SwitchAccountHelper.switchDialog(AccountActivity.this, true);
|
||||
@ -255,5 +256,11 @@ public class AccountActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
super.onBackPressed();
|
||||
overridePendingTransition(R.anim.slide_out_up, R.anim.slide_in_up_down);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -31,6 +31,7 @@ import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
@ -39,6 +40,7 @@ import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.SearchView;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.appcompat.widget.TooltipCompat;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentStatePagerAdapter;
|
||||
@ -100,7 +102,6 @@ import su.litvak.chromecast.api.v2.MediaStatus;
|
||||
|
||||
import static app.fedilab.fedilabtube.MainActivity.TypeOfConnection.NORMAL;
|
||||
import static app.fedilab.fedilabtube.MainActivity.TypeOfConnection.SURFING;
|
||||
import static app.fedilab.fedilabtube.helper.Helper.isLoggedInType;
|
||||
import static app.fedilab.fedilabtube.helper.Helper.peertubeInformation;
|
||||
|
||||
|
||||
@ -118,6 +119,7 @@ public class MainActivity extends AppCompatActivity implements ChromeCastsListen
|
||||
private DisplayVideosFragment recentFragment, locaFragment, trendingFragment, subscriptionFragment, mostLikedFragment;
|
||||
private DisplayOverviewFragment overviewFragment;
|
||||
private ActivityMainBinding binding;
|
||||
private int badgeCount;
|
||||
private final BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
|
||||
= item -> {
|
||||
int itemId = item.getItemId();
|
||||
@ -354,7 +356,7 @@ public class MainActivity extends AppCompatActivity implements ChromeCastsListen
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
typeOfConnection = TypeOfConnection.UNKNOWN;
|
||||
|
||||
badgeCount = 0;
|
||||
|
||||
binding.navView.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
|
||||
|
||||
@ -392,6 +394,11 @@ public class MainActivity extends AppCompatActivity implements ChromeCastsListen
|
||||
if (!Helper.isLoggedIn(MainActivity.this)) {
|
||||
PagerAdapter mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
|
||||
binding.viewpager.setAdapter(mPagerAdapter);
|
||||
} else {
|
||||
new Thread(() -> {
|
||||
badgeCount = new RetrofitPeertubeAPI(MainActivity.this).unreadNotifications();
|
||||
invalidateOptionsMenu();
|
||||
}).start();
|
||||
}
|
||||
binding.viewpager.setOffscreenPageLimit(5);
|
||||
|
||||
@ -454,6 +461,7 @@ public class MainActivity extends AppCompatActivity implements ChromeCastsListen
|
||||
PlaylistExportHelper.manageIntentUrl(MainActivity.this, getIntent());
|
||||
}
|
||||
|
||||
|
||||
binding.castClose.setOnClickListener(v -> {
|
||||
Intent intentBC = new Intent(Helper.RECEIVE_CAST_SETTINGS);
|
||||
Bundle b = new Bundle();
|
||||
@ -689,6 +697,18 @@ public class MainActivity extends AppCompatActivity implements ChromeCastsListen
|
||||
MenuItem accountItem = menu.findItem(R.id.action_account);
|
||||
MenuItem donateItem = menu.findItem(R.id.action_donate);
|
||||
|
||||
FrameLayout rootView = (FrameLayout) accountItem.getActionView();
|
||||
|
||||
FrameLayout redCircle = rootView.findViewById(R.id.view_alert_red_circle);
|
||||
TextView countTextView = rootView.findViewById(R.id.view_alert_count_textview);
|
||||
//change counter for notifications
|
||||
if (badgeCount > 0) {
|
||||
countTextView.setText(String.valueOf(badgeCount));
|
||||
redCircle.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
redCircle.setVisibility(View.GONE);
|
||||
}
|
||||
TooltipCompat.setTooltipText(accountItem.getActionView(), getText(R.string.account));
|
||||
if (BuildConfig.full_instances && BuildConfig.google_restriction) {
|
||||
donateItem.setVisible(true);
|
||||
}
|
||||
@ -786,6 +806,15 @@ public class MainActivity extends AppCompatActivity implements ChromeCastsListen
|
||||
}).start();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||
final MenuItem accountItem = menu.findItem(R.id.action_account);
|
||||
FrameLayout rootView = (FrameLayout) accountItem.getActionView();
|
||||
rootView.setOnClickListener(v -> onOptionsItemSelected(accountItem));
|
||||
return super.onPrepareOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
String type = null;
|
||||
@ -808,10 +837,13 @@ public class MainActivity extends AppCompatActivity implements ChromeCastsListen
|
||||
} else {
|
||||
if (Helper.canMakeAction(MainActivity.this)) {
|
||||
intent = new Intent(MainActivity.this, AccountActivity.class);
|
||||
startActivity(intent);
|
||||
overridePendingTransition(R.anim.slide_in_up, R.anim.slide_out_up);
|
||||
} else {
|
||||
intent = new Intent(MainActivity.this, LoginActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
startActivity(intent);
|
||||
|
||||
}
|
||||
} else if (item.getItemId() == R.id.action_upload) {
|
||||
Intent intent = new Intent(MainActivity.this, PeertubeUploadActivity.class);
|
||||
|
@ -284,6 +284,9 @@ public interface PeertubeService {
|
||||
@GET("users/me/notifications")
|
||||
Call<NotificationData> getNotifications(@Header("Authorization") String credentials, @Query("start") String maxId, @Query("count") String count, @Query("since_id") String sinceId);
|
||||
|
||||
@GET("users/me/notifications?start=0&count=0&unread=true")
|
||||
Call<NotificationData> countNotifications(@Header("Authorization") String credentials);
|
||||
|
||||
//Update Notification settings
|
||||
@PUT("users/me/notification-settings")
|
||||
Call<String> updateNotifications(@Header("Authorization") String credentials, @Body NotificationSettings notificationSettings);
|
||||
|
@ -283,6 +283,24 @@ public class RetrofitPeertubeAPI {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve notifications
|
||||
*
|
||||
* @return APIResponse
|
||||
*/
|
||||
public int unreadNotifications() {
|
||||
PeertubeService peertubeService = init();
|
||||
Call<NotificationData> notificationsCall = peertubeService.countNotifications("Bearer " + token);
|
||||
try {
|
||||
Response<NotificationData> response = notificationsCall.execute();
|
||||
if (response.isSuccessful() && response.body() != null) {
|
||||
return response.body().total;
|
||||
}
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve notifications
|
||||
*
|
||||
|
8
app/src/main/res/drawable/circle_red.xml
Normal file
8
app/src/main/res/drawable/circle_red.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="oval">
|
||||
<solid android:color="@android:color/holo_red_dark" />
|
||||
<size
|
||||
android:width="10dp"
|
||||
android:height="10dp" />
|
||||
</shape>
|
35
app/src/main/res/layout/counter_account_icon.xml
Normal file
35
app/src/main/res/layout/counter_account_icon.xml
Normal file
@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="32dp"
|
||||
android:layout_height="32dp"
|
||||
android:layout_gravity="center">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_gravity="center"
|
||||
android:contentDescription="@string/account"
|
||||
android:src="@drawable/ic_outline_account_circle_24" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/view_alert_red_circle"
|
||||
android:layout_width="14dp"
|
||||
android:layout_height="14dp"
|
||||
android:layout_gravity="top|end"
|
||||
android:background="@drawable/circle_red"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/view_alert_count_textview"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="10sp"
|
||||
tools:text="3" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
</FrameLayout>
|
@ -17,7 +17,7 @@
|
||||
app:showAsAction="ifRoom" />
|
||||
<item
|
||||
android:id="@+id/action_account"
|
||||
android:icon="@drawable/ic_outline_account_circle_24"
|
||||
app:actionLayout="@layout/counter_account_icon"
|
||||
android:title="@string/account"
|
||||
app:showAsAction="ifRoom" />
|
||||
<item
|
||||
|
Loading…
x
Reference in New Issue
Block a user