mirror of
https://framagit.org/tom79/fedilab-tube
synced 2025-06-05 21:09:11 +02:00
Change bottom menu depending if the user is authenticated or not
This commit is contained in:
@ -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 {
|
||||
|
Reference in New Issue
Block a user