Swap: Added splash screen to "Nearby" tab on main screen.

It doesn't load up the entire swap activity at this point. Instead it
is an entry point to direct the user to that activity.

Also added stubs for the remaining screens which need to be implemented
to the MainAdapter and MainController.
This commit is contained in:
Peter Serwylo 2017-02-21 11:17:06 +11:00
parent b151374a6c
commit 517301194b
4 changed files with 141 additions and 0 deletions

View File

@ -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;
}

View File

@ -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<MainViewController> {
// 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<MainViewController> {
@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

View File

@ -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() {
}
}

View File

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/swap_start_header"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent" />
<TextView
android:id="@+id/text1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Download apps from people near you."
android:textSize="20sp"
android:textAlignment="center"
app:layout_constraintTop_toBottomOf="@+id/image"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginTop="32dp"
android:layout_marginEnd="48dp"
android:layout_marginRight="48dp"
android:layout_marginStart="48dp"
android:layout_marginLeft="48dp" />
<!-- TODO: Use @string/app_name instead of "F-Droid". -->
<!-- TODO: The swap process helps to get F-Droid to the other user. That should probably be made a bit clearer here. -->
<TextView
android:id="@+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Participants must have F-Droid installed."
android:textSize="14sp"
android:textAlignment="center"
app:layout_constraintTop_toBottomOf="@+id/text1"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginTop="16dp"
android:layout_marginEnd="48dp"
android:layout_marginRight="48dp"
android:layout_marginStart="48dp"
android:layout_marginLeft="48dp" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Find people near me"
app:layout_constraintTop_toBottomOf="@+id/text2"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginTop="16dp" />
</android.support.constraint.ConstraintLayout>