Change bottom menu depending if the user is authenticated or not

This commit is contained in:
Thomas 2020-09-03 18:57:26 +02:00
parent c82e9e2ad2
commit c782fd14ae
9 changed files with 184 additions and 43 deletions

View File

@ -28,7 +28,10 @@ import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.SearchView; import androidx.appcompat.widget.SearchView;
import androidx.navigation.NavController; import androidx.navigation.NavController;
import androidx.navigation.NavGraph;
import androidx.navigation.NavInflater;
import androidx.navigation.Navigation; import androidx.navigation.Navigation;
import androidx.navigation.fragment.NavHostFragment;
import androidx.navigation.ui.AppBarConfiguration; import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI; import androidx.navigation.ui.NavigationUI;
@ -54,6 +57,12 @@ public class MainActivity extends AppCompatActivity {
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
BottomNavigationView navView = findViewById(R.id.nav_view); BottomNavigationView navView = findViewById(R.id.nav_view);
if (Helper.isLoggedIn(MainActivity.this)) {
navView.inflateMenu(R.menu.bottom_nav_menu_connected);
} else {
navView.inflateMenu(R.menu.bottom_nav_menu);
}
try { try {
new RetrievePeertubeInformationAsyncTask(MainActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); new RetrievePeertubeInformationAsyncTask(MainActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} catch (Exception ignored) { } catch (Exception ignored) {
@ -61,13 +70,35 @@ public class MainActivity extends AppCompatActivity {
// Passing each menu ID as a set of Ids because each // Passing each menu ID as a set of Ids because each
// menu should be considered as top level destinations. // menu should be considered as top level destinations.
AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder( AppBarConfiguration appBarConfiguration;
//Bottom menu won't be the same if the user is authenticated
//When the user is authenticated, the subscription entry will be added and the local one removed.
if (Helper.isLoggedIn(MainActivity.this)) {
appBarConfiguration = new AppBarConfiguration.Builder(
R.id.navigation_discover, R.id.navigation_subscription, R.id.navigation_trending, R.id.navigation_most_liked, R.id.navigation_recently_added)
.build();
} else {
appBarConfiguration = new AppBarConfiguration.Builder(
R.id.navigation_discover, R.id.navigation_trending, R.id.navigation_most_liked, R.id.navigation_recently_added, R.id.navigation_home) R.id.navigation_discover, R.id.navigation_trending, R.id.navigation_most_liked, R.id.navigation_recently_added, R.id.navigation_home)
.build(); .build();
}
NavHostFragment navHostFragment = (NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment);
if (navHostFragment != null) {
NavInflater inflater = navHostFragment.getNavController().getNavInflater();
NavGraph graph;
//the menu is inflated for authenticated or not authenticated account
if (Helper.isLoggedIn(MainActivity.this)) {
graph = inflater.inflate(R.navigation.mobile_navigation_connected);
} else {
graph = inflater.inflate(R.navigation.mobile_navigation);
}
navHostFragment.getNavController().setGraph(graph);
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment); NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration); NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
NavigationUI.setupWithNavController(navView, navController); NavigationUI.setupWithNavController(navView, navController);
} }
}
@Override @Override
public boolean onCreateOptionsMenu(@NotNull Menu menu) { public boolean onCreateOptionsMenu(@NotNull Menu menu) {

View File

@ -31,6 +31,7 @@ import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
@ -86,11 +87,10 @@ public class DisplayStatusFragment extends Fragment implements OnPostActionInter
private boolean ischannel; private boolean ischannel;
private View rootView; private View rootView;
private RecyclerView lv_status; private RecyclerView lv_status;
private RecyclerView lv_accounts;
private String targetedId; private String targetedId;
private boolean check_ScrollingUp; private boolean check_ScrollingUp;
private Button display_all;
private String forAccount; private String forAccount;
private ConstraintLayout top_account_container;
public DisplayStatusFragment() { public DisplayStatusFragment() {
} }
@ -124,8 +124,9 @@ public class DisplayStatusFragment extends Fragment implements OnPostActionInter
forAccount = null; forAccount = null;
lv_status = rootView.findViewById(R.id.lv_status); lv_status = rootView.findViewById(R.id.lv_status);
lv_accounts = rootView.findViewById(R.id.lv_accounts); RecyclerView lv_accounts = rootView.findViewById(R.id.lv_accounts);
display_all = rootView.findViewById(R.id.display_all); Button display_all = rootView.findViewById(R.id.display_all);
top_account_container = rootView.findViewById(R.id.top_account_container);
max_id = null; max_id = null;
max_id_accounts = null; max_id_accounts = null;
flag_loading = true; flag_loading = true;
@ -204,14 +205,14 @@ public class DisplayStatusFragment extends Fragment implements OnPostActionInter
if (type == PSUBSCRIPTIONS) { if (type == PSUBSCRIPTIONS) {
if (dy > 0) { if (dy > 0) {
if (check_ScrollingUp) { if (check_ScrollingUp) {
lv_accounts.setVisibility(View.GONE); top_account_container.setVisibility(View.GONE);
final Handler handler = new Handler(); final Handler handler = new Handler();
handler.postDelayed(() -> check_ScrollingUp = false, 300); handler.postDelayed(() -> check_ScrollingUp = false, 300);
} }
} else { } else {
if (!check_ScrollingUp) { if (!check_ScrollingUp) {
lv_accounts.setVisibility(View.VISIBLE); top_account_container.setVisibility(View.VISIBLE);
final Handler handler = new Handler(); final Handler handler = new Handler();
handler.postDelayed(() -> check_ScrollingUp = true, 300); handler.postDelayed(() -> check_ScrollingUp = true, 300);
} }
@ -316,16 +317,16 @@ public class DisplayStatusFragment extends Fragment implements OnPostActionInter
public void onRetrieveAccounts(APIResponse apiResponse) { public void onRetrieveAccounts(APIResponse apiResponse) {
if (apiResponse != null && apiResponse.getAccounts() != null && apiResponse.getAccounts().size() > 0) { if (apiResponse != null && apiResponse.getAccounts() != null && apiResponse.getAccounts().size() > 0) {
if (lv_accounts.getVisibility() == View.GONE) { if (top_account_container.getVisibility() == View.GONE) {
lv_accounts.setVisibility(View.VISIBLE); top_account_container.setVisibility(View.VISIBLE);
display_all.setVisibility(View.VISIBLE);
} }
int previousPosition = accounts.size(); int previousPosition = accounts.size();
accounts.addAll(apiResponse.getAccounts()); accounts.addAll(apiResponse.getAccounts());
accountsHorizontalListAdapter.notifyItemRangeInserted(previousPosition, apiResponse.getAccounts().size()); accountsHorizontalListAdapter.notifyItemRangeInserted(previousPosition, apiResponse.getAccounts().size());
if (max_id_accounts == null) if (max_id_accounts == null) {
max_id_accounts = "0"; max_id_accounts = "0";
//max_id needs to work like an offset }
//max_id_accounts needs to work like an offset
int tootPerPage = sharedpreferences.getInt(Helper.SET_VIDEOS_PER_PAGE, Helper.VIDEOS_PER_PAGE); int tootPerPage = sharedpreferences.getInt(Helper.SET_VIDEOS_PER_PAGE, Helper.VIDEOS_PER_PAGE);
max_id_accounts = String.valueOf(Integer.parseInt(max_id_accounts) + tootPerPage); max_id_accounts = String.valueOf(Integer.parseInt(max_id_accounts) + tootPerPage);
} }
@ -409,6 +410,12 @@ public class DisplayStatusFragment extends Fragment implements OnPostActionInter
peertubes = new ArrayList<>(); peertubes = new ArrayList<>();
max_id = "0"; max_id = "0";
peertubeAdapater.notifyItemRangeRemoved(0, size); peertubeAdapater.notifyItemRangeRemoved(0, size);
if (forAccount == null) {
for (Account account : accounts) {
account.setSelected(false);
}
accountsHorizontalListAdapter.notifyItemRangeRemoved(0, accounts.size());
}
if (search_peertube == null) { //Not a Peertube search if (search_peertube == null) { //Not a Peertube search
asyncTask = new RetrieveFeedsAsyncTask(context, type, "0", targetedId, forAccount, DisplayStatusFragment.this).execute(); asyncTask = new RetrieveFeedsAsyncTask(context, type, "0", targetedId, forAccount, DisplayStatusFragment.this).execute();
} else { } else {

View File

@ -29,8 +29,7 @@
android:background="?android:attr/windowBackground" android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent" />
app:menu="@menu/bottom_nav_menu" />
<fragment <fragment
android:id="@+id/nav_host_fragment" android:id="@+id/nav_host_fragment"

View File

@ -55,9 +55,9 @@
android:layout_marginEnd="10dp" android:layout_marginEnd="10dp"
android:contentDescription="@string/go_back" android:contentDescription="@string/go_back"
android:src="@drawable/ic_baseline_arrow_back_24" android:src="@drawable/ic_baseline_arrow_back_24"
app:tint="@android:color/white"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent"
app:tint="@android:color/white" />
<ImageView <ImageView
android:id="@+id/banner_pp" android:id="@+id/banner_pp"

View File

@ -23,12 +23,12 @@
android:orientation="vertical"> android:orientation="vertical">
<ImageView <ImageView
android:padding="2dp"
android:id="@+id/account_pp" android:id="@+id/account_pp"
android:layout_width="50dp" android:layout_width="50dp"
android:layout_height="50dp" android:layout_height="50dp"
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
android:contentDescription="@string/profile_picture" android:contentDescription="@string/profile_picture"
android:padding="2dp"
android:scaleType="centerCrop" /> android:scaleType="centerCrop" />
<TextView <TextView

View File

@ -26,33 +26,41 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:animateLayoutChanges="true" android:animateLayoutChanges="true"
tools:context=".MainActivity"> tools:context=".MainActivity">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/top_account_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintTop_toTopOf="parent">
<!-- Scrollview for displaying accounts in bubbles --> <!-- Scrollview for displaying accounts in bubbles -->
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/lv_accounts" android:id="@+id/lv_accounts"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:visibility="gone" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toLeftOf="@+id/display_all" app:layout_constraintRight_toLeftOf="@+id/display_all"
/> app:layout_constraintTop_toTopOf="parent" />
<Button <Button
android:id="@+id/display_all" android:id="@+id/display_all"
style="@style/Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="wrap_content" android:layout_width="wrap_content"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/all" android:text="@string/all"
android:visibility="gone"
app:layout_constraintLeft_toRightOf="@+id/lv_accounts"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="@+id/lv_accounts" app:layout_constraintBottom_toBottomOf="@+id/lv_accounts"
/> app:layout_constraintLeft_toRightOf="@+id/lv_accounts"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<FrameLayout <FrameLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_alignTop="@+id/lv_accounts" android:layout_alignTop="@+id/top_account_container"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/lv_accounts"> app:layout_constraintTop_toBottomOf="@+id/top_account_container">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipeContainer" android:id="@+id/swipeContainer"

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/navigation_discover"
android:icon="@drawable/ic_baseline_public_24"
android:title="@string/title_discover" />
<item
android:id="@+id/navigation_subscription"
android:icon="@drawable/ic_subscription"
android:title="@string/subscriptions" />
<item
android:id="@+id/navigation_trending"
android:icon="@drawable/ic_baseline_trending_up_24"
android:title="@string/title_trending" />
<item
android:id="@+id/navigation_most_liked"
android:icon="@drawable/ic_baseline_thumb_up_24"
android:title="@string/title_most_liked" />
<item
android:id="@+id/navigation_recently_added"
android:icon="@drawable/ic_baseline_add_circle_outline_24"
android:title="@string/title_recently_added" />
</menu>

View File

@ -0,0 +1,67 @@
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mobile_navigation"
app:startDestination="@id/navigation_discover">
<fragment
android:id="@+id/navigation_discover"
android:name="app.fedilab.fedilabtube.fragment.DisplayStatusFragment"
android:label="@string/title_discover"
tools:layout="@layout/fragment_video">
<argument
android:name="type"
android:defaultValue="POVERVIEW"
app:argType=".asynctasks.RetrieveFeedsAsyncTask$Type" />
</fragment>
<fragment
android:id="@+id/navigation_subscription"
android:name="app.fedilab.fedilabtube.fragment.DisplayStatusFragment"
android:label="@string/subscriptions"
tools:layout="@layout/fragment_video">
<argument
android:name="type"
android:defaultValue="PSUBSCRIPTIONS"
app:argType=".asynctasks.RetrieveFeedsAsyncTask$Type" />
</fragment>
<fragment
android:id="@+id/navigation_trending"
android:name="app.fedilab.fedilabtube.fragment.DisplayStatusFragment"
android:label="@string/title_trending"
tools:layout="@layout/fragment_video">
<argument
android:name="type"
android:defaultValue="PTRENDING"
app:argType=".asynctasks.RetrieveFeedsAsyncTask$Type" />
</fragment>
<fragment
android:id="@+id/navigation_most_liked"
android:name="app.fedilab.fedilabtube.fragment.DisplayStatusFragment"
android:label="@string/title_most_liked"
tools:layout="@layout/fragment_video">
<argument
android:name="type"
android:defaultValue="PMOSTLIKED"
app:argType=".asynctasks.RetrieveFeedsAsyncTask$Type" />
</fragment>
<fragment
android:id="@+id/navigation_recently_added"
android:name="app.fedilab.fedilabtube.fragment.DisplayStatusFragment"
android:label="@string/title_recently_added"
tools:layout="@layout/fragment_video">
<argument
android:name="type"
android:defaultValue="PRECENTLYADDED"
app:argType=".asynctasks.RetrieveFeedsAsyncTask$Type" />
</fragment>
</navigation>

View File

@ -174,5 +174,5 @@
<string name="successful_report">Le compte a été signalé !</string> <string name="successful_report">Le compte a été signalé !</string>
<string name="successful_video_report">La vidéo a été signalée !</string> <string name="successful_video_report">La vidéo a été signalée !</string>
<string name="report_comment_size">Veuillez préciser les raisons.</string> <string name="report_comment_size">Veuillez préciser les raisons.</string>
<string name="all">Tous</string> <string name="all">Tout</string>
</resources> </resources>