redo notification

This commit is contained in:
Thomas 2023-01-25 15:37:51 +01:00
parent e0b12ab0e2
commit 6ef2683e5e
5 changed files with 48 additions and 111 deletions

View file

@ -28,7 +28,6 @@ import android.text.SpannableString;
import android.text.Spanned; import android.text.Spanned;
import android.text.style.ForegroundColorSpan; import android.text.style.ForegroundColorSpan;
import android.text.style.UnderlineSpan; import android.text.style.UnderlineSpan;
import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
@ -55,7 +54,6 @@ import app.fedilab.android.peertube.fragment.DisplayAccountsFragment;
import app.fedilab.android.peertube.fragment.DisplayChannelsFragment; import app.fedilab.android.peertube.fragment.DisplayChannelsFragment;
import app.fedilab.android.peertube.fragment.DisplayNotificationsFragment; import app.fedilab.android.peertube.fragment.DisplayNotificationsFragment;
import app.fedilab.android.peertube.helper.Helper; import app.fedilab.android.peertube.helper.Helper;
import app.fedilab.android.peertube.helper.SwitchAccountHelper;
public class AccountActivity extends BaseBarActivity { public class AccountActivity extends BaseBarActivity {
@ -95,17 +93,14 @@ public class AccountActivity extends BaseBarActivity {
AccountData.PeertubeAccount account = baseAccount.peertube_account; AccountData.PeertubeAccount account = baseAccount.peertube_account;
setTitle(String.format("@%s", account.getUsername())); setTitle(String.format("@%s@%s", account.getUsername(), baseAccount.instance));
Helper.loadAvatar(AccountActivity.this, account, binding.profilePicture); Helper.loadAvatar(AccountActivity.this, account, binding.profilePicture);
binding.username.setText(String.format("@%s", account.getUsername())); binding.username.setText(String.format("@%s", account.getUsername()));
binding.displayname.setText(account.getDisplayName()); binding.displayname.setText(account.getDisplayName());
binding.instance.setText(account.getHost());
binding.editButton.setOnClickListener(v -> { binding.editButton.setOnClickListener(v -> startActivity(new Intent(AccountActivity.this, MyAccountActivity.class)));
startActivity(new Intent(AccountActivity.this, MyAccountActivity.class));
});
TabLayout.Tab notificationTab = binding.accountTabLayout.newTab(); TabLayout.Tab notificationTab = binding.accountTabLayout.newTab();
@ -227,11 +222,6 @@ public class AccountActivity extends BaseBarActivity {
super.onResume(); super.onResume();
} }
@Override
public boolean onCreateOptionsMenu(@NotNull Menu menu) {
getMenuInflater().inflate(R.menu.main_profile_peertube, menu);
return true;
}
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
@ -239,8 +229,6 @@ public class AccountActivity extends BaseBarActivity {
finish(); finish();
overridePendingTransition(R.anim.slide_out_up, R.anim.slide_in_up_down); overridePendingTransition(R.anim.slide_out_up, R.anim.slide_in_up_down);
return true; return true;
} else if (item.getItemId() == R.id.action_add_account) {
SwitchAccountHelper.switchDialog(AccountActivity.this, true);
} }
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }

View file

@ -19,8 +19,6 @@ import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -29,12 +27,12 @@ import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.DividerItemDecoration; import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import app.fedilab.android.R; import app.fedilab.android.R;
import app.fedilab.android.databinding.FragmentRecyclerviewPeertubeBinding;
import app.fedilab.android.peertube.client.APIResponse; import app.fedilab.android.peertube.client.APIResponse;
import app.fedilab.android.peertube.client.data.NotificationData.Notification; import app.fedilab.android.peertube.client.data.NotificationData.Notification;
import app.fedilab.android.peertube.drawer.PeertubeNotificationsListAdapter; import app.fedilab.android.peertube.drawer.PeertubeNotificationsListAdapter;
@ -69,44 +67,35 @@ public class DisplayNotificationsFragment extends Fragment {
private PeertubeNotificationsListAdapter peertubeNotificationsListAdapter; private PeertubeNotificationsListAdapter peertubeNotificationsListAdapter;
private String max_id; private String max_id;
private List<Notification> notifications; private List<Notification> notifications;
private RelativeLayout mainLoader, nextElementLoader, textviewNoAction;
private boolean firstLoad; private boolean firstLoad;
private SwipeRefreshLayout swipeRefreshLayout;
private RecyclerView lv_notifications;
private View rootView;
private NotificationsVM viewModel; private NotificationsVM viewModel;
FragmentRecyclerviewPeertubeBinding binding;
@Override @Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_recyclerview_peertube, container, false); binding = FragmentRecyclerviewPeertubeBinding.inflate(getLayoutInflater());
context = getContext(); context = getContext();
notifications = new ArrayList<>(); notifications = new ArrayList<>();
max_id = "0"; max_id = "0";
firstLoad = true; firstLoad = true;
flag_loading = true; flag_loading = true;
swipeRefreshLayout = rootView.findViewById(R.id.swipeContainer);
viewModel = new ViewModelProvider(this).get(NotificationsVM.class); viewModel = new ViewModelProvider(this).get(NotificationsVM.class);
lv_notifications = rootView.findViewById(R.id.lv_elements);
lv_notifications.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL)); binding.lvElements.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL));
mainLoader = rootView.findViewById(R.id.loader); binding.noActionText.setText(context.getString(R.string.no_notifications));
nextElementLoader = rootView.findViewById(R.id.loading_next); binding.loader.setVisibility(View.VISIBLE);
textviewNoAction = rootView.findViewById(R.id.no_action); binding.loadingNext.setVisibility(View.GONE);
TextView no_action_text = rootView.findViewById(R.id.no_action_text);
no_action_text.setText(context.getString(R.string.no_notifications));
mainLoader.setVisibility(View.VISIBLE);
nextElementLoader.setVisibility(View.GONE);
peertubeNotificationsListAdapter = new PeertubeNotificationsListAdapter(this.notifications); peertubeNotificationsListAdapter = new PeertubeNotificationsListAdapter(this.notifications);
lv_notifications.setAdapter(peertubeNotificationsListAdapter); binding.lvElements.setAdapter(peertubeNotificationsListAdapter);
final LinearLayoutManager mLayoutManager; final LinearLayoutManager mLayoutManager;
mLayoutManager = new LinearLayoutManager(context); mLayoutManager = new LinearLayoutManager(context);
lv_notifications.setLayoutManager(mLayoutManager); binding.lvElements.setLayoutManager(mLayoutManager);
lv_notifications.addOnScrollListener(new RecyclerView.OnScrollListener() { binding.lvElements.addOnScrollListener(new RecyclerView.OnScrollListener() {
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
if (dy > 0) { if (dy > 0) {
int visibleItemCount = mLayoutManager.getChildCount(); int visibleItemCount = mLayoutManager.getChildCount();
@ -116,48 +105,40 @@ public class DisplayNotificationsFragment extends Fragment {
if (!flag_loading) { if (!flag_loading) {
flag_loading = true; flag_loading = true;
viewModel.getNotifications(null, max_id).observe(DisplayNotificationsFragment.this.requireActivity(), apiResponse -> manageVIewNotifications(apiResponse)); viewModel.getNotifications(null, max_id).observe(DisplayNotificationsFragment.this.requireActivity(), apiResponse -> manageVIewNotifications(apiResponse));
nextElementLoader.setVisibility(View.VISIBLE); binding.loadingNext.setVisibility(View.VISIBLE);
} }
} else { } else {
nextElementLoader.setVisibility(View.GONE); binding.loadingNext.setVisibility(View.GONE);
} }
} }
} }
}); });
swipeRefreshLayout.setOnRefreshListener(this::pullToRefresh); binding.swipeContainer.setOnRefreshListener(this::pullToRefresh);
viewModel.getNotifications(null, "0").observe(DisplayNotificationsFragment.this.requireActivity(), this::manageVIewNotifications); viewModel.getNotifications(null, "0").observe(DisplayNotificationsFragment.this.requireActivity(), this::manageVIewNotifications);
return rootView; return binding.getRoot();
} }
@Override @Override
public void onDestroyView() { public void onDestroyView() {
super.onDestroyView(); super.onDestroyView();
rootView = null; binding = null;
} }
@Override @Override
public void onPause() { public void onPause() {
super.onPause(); super.onPause();
if (swipeRefreshLayout != null) { binding.swipeContainer.setEnabled(false);
swipeRefreshLayout.setEnabled(false); binding.swipeContainer.setRefreshing(false);
swipeRefreshLayout.setRefreshing(false); binding.swipeContainer.clearAnimation();
swipeRefreshLayout.clearAnimation();
}
} }
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
swipeRefreshLayout.setEnabled(true); binding.swipeContainer.setEnabled(true);
if (getActivity() != null && getActivity() != null) {
View action_button = getActivity().findViewById(R.id.action_button);
if (action_button != null) {
action_button.setVisibility(View.GONE);
}
}
} }
@Override @Override
@ -177,8 +158,7 @@ public class DisplayNotificationsFragment extends Fragment {
} }
public void scrollToTop() { public void scrollToTop() {
if (lv_notifications != null) binding.lvElements.setAdapter(peertubeNotificationsListAdapter);
lv_notifications.setAdapter(peertubeNotificationsListAdapter);
} }
@ -190,17 +170,17 @@ public class DisplayNotificationsFragment extends Fragment {
peertubeNotificationsListAdapter.notifyItemRangeRemoved(0, size); peertubeNotificationsListAdapter.notifyItemRangeRemoved(0, size);
firstLoad = true; firstLoad = true;
flag_loading = true; flag_loading = true;
swipeRefreshLayout.setRefreshing(true); binding.swipeContainer.setRefreshing(true);
viewModel.getNotifications(null, "0").observe(DisplayNotificationsFragment.this.requireActivity(), this::manageVIewNotifications); viewModel.getNotifications(null, "0").observe(DisplayNotificationsFragment.this.requireActivity(), this::manageVIewNotifications);
} }
private void manageVIewNotifications(APIResponse apiResponse) { private void manageVIewNotifications(APIResponse apiResponse) {
mainLoader.setVisibility(View.GONE); binding.loader.setVisibility(View.GONE);
nextElementLoader.setVisibility(View.GONE); binding.loadingNext.setVisibility(View.GONE);
if (apiResponse.getError() != null) { if (apiResponse.getError() != null) {
Toasty.error(context, apiResponse.getError().getError(), Toast.LENGTH_LONG).show(); Toasty.error(context, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
flag_loading = false; flag_loading = false;
swipeRefreshLayout.setRefreshing(false); binding.swipeContainer.setRefreshing(false);
return; return;
} }
@ -208,23 +188,23 @@ public class DisplayNotificationsFragment extends Fragment {
max_id = String.valueOf(Integer.parseInt(max_id) + 20); max_id = String.valueOf(Integer.parseInt(max_id) + 20);
List<Notification> notifications = apiResponse.getPeertubeNotifications(); List<Notification> notifications = apiResponse.getPeertubeNotifications();
if (firstLoad && (notifications == null || notifications.size() == 0)) if (firstLoad && (notifications == null || notifications.size() == 0))
textviewNoAction.setVisibility(View.VISIBLE); binding.noAction.setVisibility(View.VISIBLE);
else else
textviewNoAction.setVisibility(View.GONE); binding.noAction.setVisibility(View.GONE);
if (notifications != null && notifications.size() > 0) { if (notifications != null && notifications.size() > 0) {
this.notifications.addAll(notifications); this.notifications.addAll(notifications);
if (previousPosition == 0) { if (previousPosition == 0) {
peertubeNotificationsListAdapter = new PeertubeNotificationsListAdapter(this.notifications); peertubeNotificationsListAdapter = new PeertubeNotificationsListAdapter(this.notifications);
lv_notifications.setAdapter(peertubeNotificationsListAdapter); binding.lvElements.setAdapter(peertubeNotificationsListAdapter);
} else } else
peertubeNotificationsListAdapter.notifyItemRangeInserted(previousPosition, notifications.size()); peertubeNotificationsListAdapter.notifyItemRangeInserted(previousPosition, notifications.size());
} else { } else {
if (firstLoad) if (firstLoad)
textviewNoAction.setVisibility(View.VISIBLE); binding.noAction.setVisibility(View.VISIBLE);
} }
swipeRefreshLayout.setRefreshing(false); binding.swipeContainer.setRefreshing(false);
firstLoad = false; firstLoad = false;
//The initial call comes from a classic tab refresh //The initial call comes from a classic tab refresh
flag_loading = (max_id == null); flag_loading = (max_id == null);

View file

@ -32,34 +32,21 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:fitsSystemWindows="true" android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp" app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp" app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed"> app:layout_scrollFlags="scroll|exitUntilCollapsed">
<LinearLayout <androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical">
<TextView
android:id="@+id/instance"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:textColor="@android:color/white"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:padding="10dp"> android:padding="10dp">
<ImageView <androidx.appcompat.widget.AppCompatImageView
android:id="@+id/profile_picture" android:id="@+id/profile_picture"
android:layout_width="72dp" android:layout_width="72dp"
android:layout_height="72dp" android:layout_height="72dp"
@ -68,20 +55,19 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<TextView <androidx.appcompat.widget.AppCompatTextView
android:id="@+id/displayname" android:id="@+id/displayname"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="20dp" android:layout_marginStart="20dp"
android:ellipsize="end" android:ellipsize="end"
android:singleLine="true" android:singleLine="true"
android:textColor="@android:color/white"
android:textSize="18sp" android:textSize="18sp"
app:layout_constraintRight_toLeftOf="@+id/button_container" app:layout_constraintRight_toLeftOf="@+id/button_container"
app:layout_constraintStart_toEndOf="@+id/profile_picture" app:layout_constraintStart_toEndOf="@+id/profile_picture"
app:layout_constraintTop_toTopOf="@+id/profile_picture" /> app:layout_constraintTop_toTopOf="@+id/profile_picture" />
<TextView <androidx.appcompat.widget.AppCompatTextView
android:id="@+id/username" android:id="@+id/username"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -89,7 +75,6 @@
android:layout_marginTop="30dp" android:layout_marginTop="30dp"
android:ellipsize="end" android:ellipsize="end"
android:singleLine="true" android:singleLine="true"
android:textColor="@android:color/white"
android:textSize="14sp" android:textSize="14sp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toLeftOf="@+id/button_container" app:layout_constraintRight_toLeftOf="@+id/button_container"
@ -105,10 +90,10 @@
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"> app:layout_constraintTop_toTopOf="parent">
<Button <com.google.android.material.button.MaterialButton
android:id="@+id/edit_button" android:id="@+id/edit_button"
style="@style/Widget.AppCompat.Button.Colored" style="@style/Widget.Material3.Button"
android:layout_width="0dp" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:singleLine="true" android:singleLine="true"
android:text="@string/edit" android:text="@string/edit"
@ -116,10 +101,9 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout> </androidx.appcompat.widget.LinearLayoutCompat>
</com.google.android.material.appbar.CollapsingToolbarLayout> </com.google.android.material.appbar.CollapsingToolbarLayout>
<com.google.android.material.tabs.TabLayout <com.google.android.material.tabs.TabLayout
@ -127,12 +111,10 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:tabGravity="fill" app:tabGravity="fill"
app:tabMode="fixed" app:tabMode="fixed" />
app:tabSelectedTextColor="?colorAccent"
app:tabTextColor="@android:color/white" />
</com.google.android.material.appbar.AppBarLayout> </com.google.android.material.appbar.AppBarLayout>
<TextView <androidx.appcompat.widget.AppCompatTextView
android:id="@+id/remote_account" android:id="@+id/remote_account"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -157,7 +139,6 @@
android:layout_gravity="bottom|end" android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin" android:layout_margin="@dimen/fab_margin"
android:src="@drawable/ic_baseline_add_24" android:src="@drawable/ic_baseline_add_24"
android:tint="@android:color/white"
android:visibility="gone" android:visibility="gone"
tools:ignore="ContentDescription" /> tools:ignore="ContentDescription" />
</androidx.coordinatorlayout.widget.CoordinatorLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>

View file

@ -39,15 +39,14 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:visibility="gone"> android:visibility="gone">
<TextView <androidx.appcompat.widget.AppCompatTextView
android:id="@+id/no_action_text" android:id="@+id/no_action_text"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="center" android:layout_gravity="center"
android:gravity="center" android:gravity="center"
android:padding="10dp" android:padding="10dp"
android:text="@string/no_channels" android:text="@string/no_channels" />
android:textSize="25sp" />
</RelativeLayout> </RelativeLayout>
<!-- Main Loader --> <!-- Main Loader -->
<RelativeLayout <RelativeLayout
@ -57,11 +56,10 @@
android:gravity="center" android:gravity="center"
android:visibility="gone"> android:visibility="gone">
<com.github.ybq.android.spinkit.SpinKitView xmlns:app="http://schemas.android.com/apk/res-auto" <ProgressBar
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center" />
app:SpinKit_Color="?colorAccent" />
</RelativeLayout> </RelativeLayout>
<!-- Loader for next accounts --> <!-- Loader for next accounts -->
<RelativeLayout <RelativeLayout
@ -73,11 +71,10 @@
android:gravity="bottom|center_horizontal" android:gravity="bottom|center_horizontal"
android:visibility="gone"> android:visibility="gone">
<com.github.ybq.android.spinkit.SpinKitView xmlns:app="http://schemas.android.com/apk/res-auto" <ProgressBar
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center" />
app:SpinKit_Color="?colorAccent" />
</RelativeLayout> </RelativeLayout>
</RelativeLayout> </RelativeLayout>

View file

@ -1,9 +0,0 @@
<?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/action_add_account"
android:icon="@drawable/ic_baseline_person_add_24"
android:title="@string/add_account"
app:showAsAction="ifRoom" />
</menu>