diff --git a/app/src/main/java/org/fdroid/fdroid/views/main/MainActivity.java b/app/src/main/java/org/fdroid/fdroid/views/main/MainActivity.java index 011cc2716..4bef94cef 100644 --- a/app/src/main/java/org/fdroid/fdroid/views/main/MainActivity.java +++ b/app/src/main/java/org/fdroid/fdroid/views/main/MainActivity.java @@ -46,6 +46,7 @@ public class MainActivity extends AppCompatActivity implements BottomNavigationV @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { + pager.scrollToPosition(MainViewAdapter.ID_TO_POSITION.get(item.getItemId())); return true; } diff --git a/app/src/main/java/org/fdroid/fdroid/views/main/MainViewAdapter.java b/app/src/main/java/org/fdroid/fdroid/views/main/MainViewAdapter.java index 7d01442d8..79f75ed0c 100644 --- a/app/src/main/java/org/fdroid/fdroid/views/main/MainViewAdapter.java +++ b/app/src/main/java/org/fdroid/fdroid/views/main/MainViewAdapter.java @@ -2,9 +2,12 @@ package org.fdroid.fdroid.views.main; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.RecyclerView; +import android.util.SparseIntArray; import android.view.ViewGroup; import android.widget.FrameLayout; +import org.fdroid.fdroid.R; + /** * Represents the five main views that are accessible from the main view. These are: * + Whats new @@ -22,6 +25,27 @@ import android.widget.FrameLayout; */ class MainViewAdapter extends RecyclerView.Adapter { + // Helpers for switching between the API of the RecyclerViewPager and the BottomNavigationView. + // One identifies items by position, the other by menu item ID, yet they need to be able + // to talk to and control each other. If the user swipes the view pager, the bottom nav needs + // to update, and vice-versa. + static final SparseIntArray ID_TO_POSITION = new SparseIntArray(); + static final SparseIntArray POSITION_TO_ID = new SparseIntArray(); + + static { + ID_TO_POSITION.put(R.id.whats_new, 0); + ID_TO_POSITION.put(R.id.categories, 1); + ID_TO_POSITION.put(R.id.nearby, 2); + ID_TO_POSITION.put(R.id.my_apps, 3); + ID_TO_POSITION.put(R.id.settings, 4); + + POSITION_TO_ID.put(0, R.id.whats_new); + POSITION_TO_ID.put(1, R.id.categories); + POSITION_TO_ID.put(2, R.id.nearby); + POSITION_TO_ID.put(3, R.id.my_apps); + POSITION_TO_ID.put(4, R.id.settings); + } + private final AppCompatActivity activity; MainViewAdapter(AppCompatActivity activity) { @@ -37,6 +61,20 @@ class MainViewAdapter extends RecyclerView.Adapter { @Override public void onBindViewHolder(MainViewController holder, int position) { + int menuId = POSITION_TO_ID.get(position); + if (menuId == R.id.whats_new) { + holder.bindWhatsNewView(); + } else if (menuId == R.id.categories) { + holder.bindCategoriesView(); + } else if (menuId == R.id.nearby) { + holder.bindSwapView(); + } else if (menuId == R.id.my_apps) { + holder.bindMyApps(); + } else if (menuId == R.id.settings) { + holder.bindSettingsView(); + } else { + holder.clearViews(); + } } @Override diff --git a/app/src/main/java/org/fdroid/fdroid/views/main/MainViewController.java b/app/src/main/java/org/fdroid/fdroid/views/main/MainViewController.java index 572c58d57..690dfce6c 100644 --- a/app/src/main/java/org/fdroid/fdroid/views/main/MainViewController.java +++ b/app/src/main/java/org/fdroid/fdroid/views/main/MainViewController.java @@ -1,9 +1,15 @@ package org.fdroid.fdroid.views.main; +import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.RecyclerView; +import android.view.View; +import android.widget.Button; import android.widget.FrameLayout; +import org.fdroid.fdroid.R; +import org.fdroid.fdroid.views.swap.SwapWorkflowActivity; + /** * Decides which view on the main screen to attach to a given {@link FrameLayout}. This class * doesn't know which view it will be rendering at the time it is constructed. Rather, at some @@ -21,4 +27,38 @@ class MainViewController extends RecyclerView.ViewHolder { this.frame = frame; } + public void clearViews() { + frame.removeAllViews(); + } + + public void bindWhatsNewView() { + } + + public void bindMyApps() { + } + + public void bindCategoriesView() { + } + + /** + * A splash screen encouraging people to start the swap process. + * The swap process is quite heavy duty in that it fires up Bluetooth and/or WiFi in + * order to scan for peers. As such, it is quite convenient to have a more lightweight view to show + * in the main navigation that doesn't automatically start doing things when the user touches the + * navigation menu in the bottom navigation. + */ + public void bindSwapView() { + View swapView = activity.getLayoutInflater().inflate(R.layout.main_tab_swap, frame, true); + + Button startButton = (Button) swapView.findViewById(R.id.button); + startButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + activity.startActivity(new Intent(activity, SwapWorkflowActivity.class)); + } + }); + } + + public void bindSettingsView() { + } } diff --git a/app/src/main/res/layout/main_tab_swap.xml b/app/src/main/res/layout/main_tab_swap.xml new file mode 100644 index 000000000..a7f010b06 --- /dev/null +++ b/app/src/main/res/layout/main_tab_swap.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + +