Introduce new main activity, currently mostly empty.

This activity so far has a bottom navigation bar with 5 tabs.
The tabs can be changed, but no content is shown.
This commit is contained in:
Peter Serwylo 2017-02-21 11:34:07 +11:00
parent f0d4f8f01a
commit b151374a6c
12 changed files with 246 additions and 6 deletions

View File

@ -137,12 +137,6 @@
android:configChanges="layoutDirection|locale|keyboardHidden|orientation|screenSize" >
<!-- App URLs -->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
@ -506,6 +500,15 @@
<service
android:name=".data.InstalledAppProviderService"
android:exported="false" />
<activity android:name=".views.main.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

View File

@ -0,0 +1,68 @@
package org.fdroid.fdroid.views.main;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.view.MenuItem;
import android.support.v7.widget.RecyclerView;
import org.fdroid.fdroid.R;
/**
* Main view shown to users upon starting F-Droid.
*
* Shows a bottom navigation bar, with the following entries:
* + Whats new
* + Categories list
* + App swap
* + My apps
* + Settings
*
* Users navigate between items by using the bottom navigation bar, or by swiping left and right.
* When switching from one screen to the next, we stay within this activity. The new screen will
* get inflated (if required)
*/
public class MainActivity extends AppCompatActivity implements BottomNavigationView.OnNavigationItemSelectedListener {
private RecyclerView pager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pager = (RecyclerView) findViewById(R.id.main_view_pager);
pager.setHasFixedSize(true);
pager.setLayoutManager(new NonScrollingHorizontalLayoutManager(this));
pager.setAdapter(new MainViewAdapter(this));
BottomNavigationView bottomNavigation = (BottomNavigationView) findViewById(R.id.bottom_navigation);
bottomNavigation.setOnNavigationItemSelectedListener(this);
}
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
return true;
}
private static class NonScrollingHorizontalLayoutManager extends LinearLayoutManager {
NonScrollingHorizontalLayoutManager(Context context) {
super(context, LinearLayoutManager.HORIZONTAL, false);
}
@Override
public boolean canScrollHorizontally() {
return false;
}
@Override
public boolean canScrollVertically() {
return false;
}
}
}

View File

@ -0,0 +1,46 @@
package org.fdroid.fdroid.views.main;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;
import android.widget.FrameLayout;
/**
* Represents the five main views that are accessible from the main view. These are:
* + Whats new
* + Categories
* + Nearby
* + My Apps
* + Settings
*
* It is responsible for understanding the relationship between each main view that is reachable
* from the bottom navigation, and its position.
*
* It doesn't need to do very much other than redirect requests from the {@link MainActivity}s
* {@link RecyclerView} to the relevant "bind*()" method
* of the {@link MainViewController}.
*/
class MainViewAdapter extends RecyclerView.Adapter<MainViewController> {
private final AppCompatActivity activity;
MainViewAdapter(AppCompatActivity activity) {
this.activity = activity;
}
@Override
public MainViewController onCreateViewHolder(ViewGroup parent, int viewType) {
FrameLayout frame = new FrameLayout(activity);
frame.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
return new MainViewController(activity, frame);
}
@Override
public void onBindViewHolder(MainViewController holder, int position) {
}
@Override
public int getItemCount() {
return 5;
}
}

View File

@ -0,0 +1,24 @@
package org.fdroid.fdroid.views.main;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.widget.FrameLayout;
/**
* 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
* point in the future the {@link MainViewAdapter} will have information about which view we
* are required to render, and will invoke the relevant "bind*()" method on this class.
*/
class MainViewController extends RecyclerView.ViewHolder {
private final AppCompatActivity activity;
private final FrameLayout frame;
MainViewController(AppCompatActivity activity, FrameLayout frame) {
super(frame);
this.activity = activity;
this.frame = frame;
}
}

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M20,6h-8l-2,-2L4,4c-1.1,0 -1.99,0.9 -1.99,2L2,18c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,8c0,-1.1 -0.9,-2 -2,-2zM20,18L4,18L4,8h16v10z"/>
</vector>

View File

@ -0,0 +1,6 @@
<vector android:height="24dp" android:viewportHeight="64.0"
android:viewportWidth="64.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillAlpha="1" android:fillColor="#ffffff"
android:pathData="m32,0a32,32 0,0 0,-32 32,32 32,0 0,0 32,32 32,32 0,0 0,32 -32,32 32,0 0,0 -32,-32zM32.56,10.63a9.46,9.46 0,0 1,9.46 9.46,9.46 9.46,0 0,1 -9.46,9.46 9.46,9.46 0,0 1,-9.46 -9.46,9.46 9.46,0 0,1 9.46,-9.46zM32,36.45a33.39,33.39 0,0 1,20.37 6.98,23.37 23.37,0 0,1 -20.37,11.94 23.37,23.37 0,0 1,-20.37 -11.96,33.39 33.39,0 0,1 20.37,-6.96z"
android:strokeAlpha="1" android:strokeColor="#00000000" android:strokeWidth="2"/>
</vector>

View File

@ -0,0 +1,12 @@
<vector android:height="24dp" android:viewportHeight="64.0"
android:viewportWidth="64.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillAlpha="1" android:fillColor="#ffffff"
android:pathData="m31.52,0.48a31.52,31.52 45.69,0 0,-31.52 31.52,31.52 31.52,45.64 0,0 0.45,5.11 16.53,16.53 53.72,0 1,4.52 -2.34,26.71 26.71,48.01 0,1 -0.18,-2.78 26.71,26.71 49.01,0 1,26.72 -26.71,26.71 26.71,48.46 0,1 23.41,13.91 14.8,14.8 67.3,0 1,2.73 -0.26,14.8 14.8,67.32 0,1 2.62,0.24 31.52,31.52 0,0 0,-28.76 -18.69zM31.52,14.32a17.68,17.68 99.47,0 0,-17.68 17.68,17.68 17.68,99.47 0,0 0.18,2.39 16.53,16.53 53.72,0 1,12.62 14.6,17.68 17.68,99.47 0,0 4.88,0.69 17.68,17.68 99.2,0 0,14.22 -7.21,14.8 14.8,66.35 0,1 -2.88,-8.75 14.8,14.8 67.3,0 1,4.14 -10.27,17.68 17.68,99.2 0,0 -15.48,-9.15zM31.52,21.62a10.38,10.38 75.21,0 1,10.38 10.38,10.38 10.38,75.3 0,1 -10.38,10.38 10.38,10.38 76.55,0 1,-10.38 -10.38,10.38 10.38,76.21 0,1 10.38,-10.38zM53.04,47.77a26.71,26.71 48.42,0 1,-21.52 10.94,26.71 26.71,48.96 0,1 -6.56,-0.85 16.53,16.53 54.54,0 1,-2.96 4.15,31.52 31.52,45.67 0,0 9.52,1.51 31.52,31.52 47.06,0 0,26.83 -15.03,14.8 14.8,67.3 0,1 -0.69,0.04 14.8,14.8 67.32,0 1,-4.61 -0.76z"
android:strokeAlpha="1" android:strokeColor="#00000000" android:strokeWidth="2"/>
<path android:fillAlpha="1" android:fillColor="#ffffff"
android:pathData="M10.19,50.45m-7.88,0a7.88,7.88 53.72,1 1,15.76 0a7.88,7.88 53.29,1 1,-15.76 0"
android:strokeAlpha="1" android:strokeColor="#00000000" android:strokeWidth="2"/>
<path android:fillAlpha="1" android:fillColor="#ffffff"
android:pathData="M57.66,33.73m-6.34,0a6.34,6.34 114.83,1 1,12.68 0a6.34,6.34 114.83,1 1,-12.68 0"
android:strokeAlpha="1" android:strokeColor="#00000000" android:strokeWidth="2"/>
</vector>

View File

@ -0,0 +1,6 @@
<vector android:height="24dp" android:viewportHeight="64.0"
android:viewportWidth="64.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillAlpha="1" android:fillColor="#ffffff"
android:pathData="m40.15,0.71 l-9.57,5.97 -10.14,-4.94 -4.23,10.45 -11.11,1.96 2.72,10.95 -7.83,8.11 8.63,7.25 -1.56,11.17 11.25,0.79 5.3,9.95 9.57,-5.97 10.14,4.94 4.23,-10.45 11.11,-1.96 -2.72,-10.94 7.83,-8.12 -8.63,-7.25 1.56,-11.17 -11.25,-0.79 -5.3,-9.95zM28.45,15.95 L34.06,15.95 34.06,32.52 28.45,32.52 28.45,15.95zM28.45,38 L34.06,38 34.06,43.6 28.45,43.6 28.45,38z"
android:strokeAlpha="1" android:strokeColor="#00000000" android:strokeWidth="2"/>
</vector>

View File

@ -0,0 +1,6 @@
<vector android:height="24dp" android:viewportHeight="64.0"
android:viewportWidth="64.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillAlpha="1" android:fillColor="#ffffff"
android:pathData="m23.4,0.01 l0,8.54c0.02,1.79 -5.02,5.64 -7.4,4.27l-7.4,-4.27 -8.6,14.9 7.4,4.27c2.65,1.48 2.93,6.85 0,8.54l-7.4,4.27 8.6,14.9 7.4,-4.27c2.29,-1.36 7.4,0.81 7.4,4.27l0,8.55 17.2,0 0,-8.55c0,-3.23 4.16,-6.14 7.4,-4.27l7.4,4.27 8.6,-14.9 -7.4,-4.27c-2.47,-1.43 -2.98,-6.82 0,-8.54l7.4,-4.27 -8.6,-14.9 -7.4,4.27c-2.16,1.29 -7.4,-0.67 -7.4,-4.27l0,-8.54 -17.2,0zM32.14,20.4a11.76,11.76 0,0 1,11.76 11.76,11.76 11.76,0 0,1 -11.76,11.76 11.76,11.76 0,0 1,-11.75 -11.76,11.76 11.76,0 0,1 11.75,-11.76z"
android:strokeAlpha="1" android:strokeColor="#00000000" android:strokeWidth="2"/>
</vector>

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:menu="@menu/main_activity_screens"
app:itemBackground="@color/fdroid_blue"
app:itemIconTint="@android:color/white"
app:itemTextColor="@android:color/white" />
<android.support.v7.widget.RecyclerView
android:id="@+id/main_view_pager"
android:layout_alignParentTop="true"
android:layout_above="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:title="@string/main_menu__latest_apps"
android:icon="@drawable/ic_overview"
app:showAsAction="ifRoom"
android:id="@+id/whats_new" />
<item
android:title="@string/main_menu__categories"
android:icon="@drawable/ic_category"
app:showAsAction="ifRoom"
android:id="@+id/categories" />
<item
android:title="@string/main_menu__swap_nearby"
android:icon="@drawable/ic_nearby"
app:showAsAction="ifRoom"
android:id="@+id/nearby" />
<item
android:title="@string/main_menu__my_apps"
android:icon="@drawable/ic_my_apps"
app:showAsAction="ifRoom"
android:id="@+id/my_apps" />
<item
android:title="@string/menu_settings"
android:icon="@drawable/ic_settings"
app:showAsAction="ifRoom"
android:id="@+id/settings" />
</menu>

View File

@ -130,6 +130,11 @@
<string name="menu_litecoin">Litecoin</string>
<string name="menu_flattr">Flattr</string>
<string name="main_menu__latest_apps">Latest</string>
<string name="main_menu__categories">Categories</string>
<string name="main_menu__swap_nearby">Nearby</string>
<string name="main_menu__my_apps">My Apps</string>
<string name="details_installed">Version %s installed</string>
<string name="details_notinstalled">Not installed</string>