Change bottom menu depending if the user is authenticated or not
This commit is contained in:
parent
c82e9e2ad2
commit
c782fd14ae
|
@ -28,7 +28,10 @@ import androidx.appcompat.app.AlertDialog;
|
|||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.SearchView;
|
||||
import androidx.navigation.NavController;
|
||||
import androidx.navigation.NavGraph;
|
||||
import androidx.navigation.NavInflater;
|
||||
import androidx.navigation.Navigation;
|
||||
import androidx.navigation.fragment.NavHostFragment;
|
||||
import androidx.navigation.ui.AppBarConfiguration;
|
||||
import androidx.navigation.ui.NavigationUI;
|
||||
|
||||
|
@ -54,6 +57,12 @@ public class MainActivity extends AppCompatActivity {
|
|||
setContentView(R.layout.activity_main);
|
||||
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 {
|
||||
new RetrievePeertubeInformationAsyncTask(MainActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
} catch (Exception ignored) {
|
||||
|
@ -61,12 +70,34 @@ public class MainActivity extends AppCompatActivity {
|
|||
|
||||
// Passing each menu ID as a set of Ids because each
|
||||
// menu should be considered as top level destinations.
|
||||
AppBarConfiguration 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)
|
||||
.build();
|
||||
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
|
||||
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
|
||||
NavigationUI.setupWithNavController(navView, navController);
|
||||
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)
|
||||
.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);
|
||||
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
|
||||
NavigationUI.setupWithNavController(navView, navController);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -31,6 +31,7 @@ import android.widget.TextView;
|
|||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
|
@ -86,11 +87,10 @@ public class DisplayStatusFragment extends Fragment implements OnPostActionInter
|
|||
private boolean ischannel;
|
||||
private View rootView;
|
||||
private RecyclerView lv_status;
|
||||
private RecyclerView lv_accounts;
|
||||
private String targetedId;
|
||||
private boolean check_ScrollingUp;
|
||||
private Button display_all;
|
||||
private String forAccount;
|
||||
private ConstraintLayout top_account_container;
|
||||
|
||||
public DisplayStatusFragment() {
|
||||
}
|
||||
|
@ -124,8 +124,9 @@ public class DisplayStatusFragment extends Fragment implements OnPostActionInter
|
|||
|
||||
forAccount = null;
|
||||
lv_status = rootView.findViewById(R.id.lv_status);
|
||||
lv_accounts = rootView.findViewById(R.id.lv_accounts);
|
||||
display_all = rootView.findViewById(R.id.display_all);
|
||||
RecyclerView lv_accounts = rootView.findViewById(R.id.lv_accounts);
|
||||
Button display_all = rootView.findViewById(R.id.display_all);
|
||||
top_account_container = rootView.findViewById(R.id.top_account_container);
|
||||
max_id = null;
|
||||
max_id_accounts = null;
|
||||
flag_loading = true;
|
||||
|
@ -204,14 +205,14 @@ public class DisplayStatusFragment extends Fragment implements OnPostActionInter
|
|||
if (type == PSUBSCRIPTIONS) {
|
||||
if (dy > 0) {
|
||||
if (check_ScrollingUp) {
|
||||
lv_accounts.setVisibility(View.GONE);
|
||||
top_account_container.setVisibility(View.GONE);
|
||||
final Handler handler = new Handler();
|
||||
handler.postDelayed(() -> check_ScrollingUp = false, 300);
|
||||
|
||||
}
|
||||
} else {
|
||||
if (!check_ScrollingUp) {
|
||||
lv_accounts.setVisibility(View.VISIBLE);
|
||||
top_account_container.setVisibility(View.VISIBLE);
|
||||
final Handler handler = new Handler();
|
||||
handler.postDelayed(() -> check_ScrollingUp = true, 300);
|
||||
}
|
||||
|
@ -316,16 +317,16 @@ public class DisplayStatusFragment extends Fragment implements OnPostActionInter
|
|||
public void onRetrieveAccounts(APIResponse apiResponse) {
|
||||
|
||||
if (apiResponse != null && apiResponse.getAccounts() != null && apiResponse.getAccounts().size() > 0) {
|
||||
if (lv_accounts.getVisibility() == View.GONE) {
|
||||
lv_accounts.setVisibility(View.VISIBLE);
|
||||
display_all.setVisibility(View.VISIBLE);
|
||||
if (top_account_container.getVisibility() == View.GONE) {
|
||||
top_account_container.setVisibility(View.VISIBLE);
|
||||
}
|
||||
int previousPosition = accounts.size();
|
||||
accounts.addAll(apiResponse.getAccounts());
|
||||
accountsHorizontalListAdapter.notifyItemRangeInserted(previousPosition, apiResponse.getAccounts().size());
|
||||
if (max_id_accounts == null)
|
||||
if (max_id_accounts == null) {
|
||||
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);
|
||||
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<>();
|
||||
max_id = "0";
|
||||
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
|
||||
asyncTask = new RetrieveFeedsAsyncTask(context, type, "0", targetedId, forAccount, DisplayStatusFragment.this).execute();
|
||||
} else {
|
||||
|
|
|
@ -29,8 +29,7 @@
|
|||
android:background="?android:attr/windowBackground"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:menu="@menu/bottom_nav_menu" />
|
||||
app:layout_constraintRight_toRightOf="parent" />
|
||||
|
||||
<fragment
|
||||
android:id="@+id/nav_host_fragment"
|
||||
|
|
|
@ -55,9 +55,9 @@
|
|||
android:layout_marginEnd="10dp"
|
||||
android:contentDescription="@string/go_back"
|
||||
android:src="@drawable/ic_baseline_arrow_back_24"
|
||||
app:tint="@android:color/white"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:tint="@android:color/white" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/banner_pp"
|
||||
|
|
|
@ -23,12 +23,12 @@
|
|||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
android:padding="2dp"
|
||||
android:id="@+id/account_pp"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="50dp"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:contentDescription="@string/profile_picture"
|
||||
android:padding="2dp"
|
||||
android:scaleType="centerCrop" />
|
||||
|
||||
<TextView
|
||||
|
|
|
@ -26,33 +26,41 @@
|
|||
android:layout_height="match_parent"
|
||||
android:animateLayoutChanges="true"
|
||||
tools:context=".MainActivity">
|
||||
<!-- Scrollview for displaying accounts in bubbles -->
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/lv_accounts"
|
||||
android:layout_width="0dp"
|
||||
|
||||
<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"
|
||||
app:layout_constraintRight_toLeftOf="@+id/display_all"
|
||||
/>
|
||||
<Button
|
||||
android:id="@+id/display_all"
|
||||
android:layout_width="wrap_content"
|
||||
style="@style/Widget.AppCompat.Button.Borderless"
|
||||
android:layout_height="wrap_content"
|
||||
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_constraintTop_toTopOf="parent">
|
||||
<!-- Scrollview for displaying accounts in bubbles -->
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/lv_accounts"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toLeftOf="@+id/display_all"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/display_all"
|
||||
style="@style/Widget.AppCompat.Button.Borderless.Colored"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/all"
|
||||
|
||||
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
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_alignTop="@+id/lv_accounts"
|
||||
android:layout_alignTop="@+id/top_account_container"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/lv_accounts">
|
||||
app:layout_constraintTop_toBottomOf="@+id/top_account_container">
|
||||
|
||||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
android:id="@+id/swipeContainer"
|
||||
|
|
|
@ -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>
|
|
@ -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>
|
|
@ -174,5 +174,5 @@
|
|||
<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="report_comment_size">Veuillez préciser les raisons.</string>
|
||||
<string name="all">Tous</string>
|
||||
<string name="all">Tout</string>
|
||||
</resources>
|
Loading…
Reference in New Issue