Bug 1289242 - Implement basic ActivityStream-detail activity r?sebastian
This depends largely on the implementation of a modified Bookmarks
list in
Bug 1288127.
MozReview-Commit-ID: 2QeLsZ6MFvL
--- a/mobile/android/base/AndroidManifest.xml.in
+++ b/mobile/android/base/AndroidManifest.xml.in
@@ -270,16 +270,19 @@
</activity>
#endif
<activity android:name="org.mozilla.gecko.preferences.GeckoPreferences"
android:theme="@style/Gecko.Preferences"
android:configChanges="orientation|screenSize|locale|layoutDirection"
android:excludeFromRecents="true"/>
+ <activity android:name="org.mozilla.gecko.home.activitystream.ASDetailActivity"
+ android:theme="@style/Gecko"/>
+
<provider android:name="org.mozilla.gecko.db.BrowserProvider"
android:authorities="@ANDROID_PACKAGE_NAME@.db.browser"
android:exported="false"/>
<provider android:name="org.mozilla.gecko.distribution.PartnerBookmarksProviderProxy"
android:authorities="@ANDROID_PACKAGE_NAME@.partnerbookmarks"
android:exported="false"/>
--- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
@@ -50,16 +50,17 @@ import org.mozilla.gecko.home.HomeConfig
import org.mozilla.gecko.home.HomeConfigPrefsBackend;
import org.mozilla.gecko.home.HomeFragment;
import org.mozilla.gecko.home.HomePager.OnUrlOpenInBackgroundListener;
import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
import org.mozilla.gecko.home.HomePanelsManager;
import org.mozilla.gecko.home.HomeScreen;
import org.mozilla.gecko.home.SearchEngine;
import org.mozilla.gecko.home.activitystream.ASOpenURLDelegate;
+import org.mozilla.gecko.home.activitystream.ActivityStream;
import org.mozilla.gecko.javaaddons.JavaAddonManager;
import org.mozilla.gecko.media.AudioFocusAgent;
import org.mozilla.gecko.menu.GeckoMenu;
import org.mozilla.gecko.menu.GeckoMenuItem;
import org.mozilla.gecko.mozglue.SafeIntent;
import org.mozilla.gecko.notifications.NotificationClient;
import org.mozilla.gecko.notifications.ServiceNotificationClient;
import org.mozilla.gecko.overlays.ui.ShareDialog;
@@ -2711,17 +2712,19 @@ public class BrowserApp extends GeckoApp
// onMetricsChanged callback still works.
if (mDynamicToolbar.isEnabled()) {
mDynamicToolbar.setVisible(true, VisibilityTransition.IMMEDIATE);
}
if (mHomeScreen == null) {
if (org.mozilla.gecko.activitystream.ActivityStream.isEnabled(this)) {
final ViewStub asStub = (ViewStub) findViewById(R.id.activity_stream_stub);
- mHomeScreen = (HomeScreen) asStub.inflate();
+ ActivityStream activityStream = (ActivityStream) asStub.inflate();
+ activityStream.setBrowserApp(this);
+ mHomeScreen = activityStream;
} else {
final ViewStub homePagerStub = (ViewStub) findViewById(R.id.home_pager_stub);
mHomeScreen = (HomeScreen) homePagerStub.inflate();
// For now these listeners are HomePager specific. In future we might want
// to have a more abstracted data storage, with one Bundle containing all
// relevant restore data.
mHomeScreen.setOnPanelChangeListener(new HomeScreen.OnPanelChangeListener() {
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/java/org/mozilla/gecko/home/activitystream/ASDetailActivity.java
@@ -0,0 +1,120 @@
+/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+package org.mozilla.gecko.home.activitystream;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.support.annotation.Nullable;
+import android.support.design.widget.TabLayout;
+import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentManager;
+import android.support.v4.app.FragmentPagerAdapter;
+import android.support.v4.view.ViewPager;
+import android.support.v7.app.AppCompatActivity;
+import android.view.View;
+import android.widget.Button;
+import android.widget.ImageView;
+
+import org.mozilla.gecko.R;
+import org.mozilla.gecko.home.CombinedHistoryPanel;
+import org.mozilla.gecko.home.HomeFragment;
+import org.mozilla.gecko.home.HomePager;
+
+import java.util.EnumSet;
+
+/**
+ * Detail view for history/bookmarks/synced-tabs etc.
+ */
+public class ASDetailActivity
+ extends AppCompatActivity
+ implements HomePager.OnUrlOpenListener, HomePager.OnUrlOpenInBackgroundListener {
+
+ enum PanelType {
+ HISTORY,
+ BOOKMARKS
+ }
+
+ private static class DetailFragmentPager extends FragmentPagerAdapter {
+ private final Context context;
+
+ public DetailFragmentPager(FragmentManager fragmentManager, Context context) {
+ super(fragmentManager);
+
+ this.context = context;
+ }
+
+ @Override
+ public Fragment getItem(int position) {
+ PanelType panelType = PanelType.values()[position];
+
+ switch (panelType) {
+ case HISTORY:
+ return new CombinedHistoryPanel();
+ case BOOKMARKS:
+ HomeFragment bookmarksPanel = new CombinedHistoryPanel();
+
+ Bundle args = new Bundle();
+ args.putBoolean(CombinedHistoryPanel.ARG_BOOKMARKS_MODE, true);
+ bookmarksPanel.setArguments(args);
+
+ return bookmarksPanel;
+ default:
+ throw new IllegalArgumentException("Invalid position supplied");
+ }
+ }
+
+ @Override
+ public int getCount() {
+ return PanelType.values().length;
+ }
+
+ @Override
+ public CharSequence getPageTitle(int position) {
+ PanelType panelType = PanelType.values()[position];
+
+ switch (panelType) {
+ case HISTORY:
+ return context.getResources().getString(R.string.history_title);
+ case BOOKMARKS:
+ return context.getResources().getString(R.string.bookmarks_title);
+ default:
+ throw new IllegalArgumentException("Invalid position supplied");
+ }
+ }
+ }
+
+ @Override
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ setContentView(R.layout.as_detail_activity);
+
+ ViewPager pager = (ViewPager) findViewById(R.id.as_pager);
+
+ pager.setAdapter(new DetailFragmentPager(getSupportFragmentManager(), this));
+
+ TabLayout tabLayout = (TabLayout) findViewById(R.id.as_detail_tablayout);
+ tabLayout.setupWithViewPager(pager);
+
+ final ImageView exitButton = (ImageView) findViewById(R.id.as_close_button);
+ exitButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ finish();
+ }
+ });
+ }
+
+ @Override
+ public void onUrlOpen(String url, EnumSet<HomePager.OnUrlOpenListener.Flags> flags) {
+ ASOpenURLDelegate.openURL(this, url, flags);
+ }
+
+ @Override
+ public void onUrlOpenInBackground(String url,
+ EnumSet<HomePager.OnUrlOpenInBackgroundListener.Flags> flags) {
+ ASOpenURLDelegate.openInBackground(this, url, flags);
+ }
+}
--- a/mobile/android/base/java/org/mozilla/gecko/home/activitystream/ActivityStream.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/activitystream/ActivityStream.java
@@ -1,33 +1,44 @@
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.home.activitystream;
import android.content.Context;
+import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.LoaderManager;
import android.util.AttributeSet;
import android.widget.FrameLayout;
-import android.widget.LinearLayout;
+
+import org.mozilla.gecko.BrowserApp;
+import org.mozilla.gecko.R;
import org.mozilla.gecko.animation.PropertyAnimator;
import org.mozilla.gecko.home.HomeBanner;
import org.mozilla.gecko.home.HomeFragment;
import org.mozilla.gecko.home.HomeScreen;
+import java.lang.ref.WeakReference;
+
public class ActivityStream extends FrameLayout implements HomeScreen {
public ActivityStream(Context context, AttributeSet attrs) {
super(context, attrs);
}
+ private WeakReference<BrowserApp> browserAppWeakReference = new WeakReference<BrowserApp>(null);
+
+ public void setBrowserApp(final BrowserApp browserApp) {
+ this.browserAppWeakReference = new WeakReference<>(browserApp);
+ }
+
@Override
public boolean isVisible() {
// This is dependent on the loading state - currently we're a dumb panel so we're always
// "visible"
return true;
}
@Override
@@ -61,9 +72,20 @@ public class ActivityStream extends Fram
PropertyAnimator animator) {
// Signal to load data from storage as needed, compare with HomePager
}
@Override
public void unload() {
// Signal to clear data that has been loaded, compare with HomePager
}
+
+ private void openDetailView() {
+ BrowserApp browserApp = browserAppWeakReference.get();
+
+ if (browserApp == null) {
+ return;
+ }
+
+ Intent i = new Intent(getContext(), ASDetailActivity.class);
+ browserApp.startActivityForResult(i, BrowserApp.ACTIVITY_REQUEST_AS_DETAIL);
+ }
}
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -434,16 +434,17 @@ gbjar.sources += ['java/org/mozilla/geck
'GeckoProfilesProvider.java',
'GeckoUpdateReceiver.java',
'GlobalHistory.java',
'GuestSession.java',
'health/HealthRecorder.java',
'health/SessionInformation.java',
'health/StubbedHealthRecorder.java',
'home/activitystream/ActivityStream.java',
+ 'home/activitystream/ASDetailActivity.java',
'home/activitystream/ASOpenURLDelegate.java',
'home/BookmarkFolderView.java',
'home/BookmarkScreenshotRow.java',
'home/BookmarksListAdapter.java',
'home/BookmarksListView.java',
'home/BookmarksPanel.java',
'home/BrowserSearch.java',
'home/ClientsAdapter.java',
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/resources/layout/as_detail_activity.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <LinearLayout
+ android:id="@+id/topbar"
+ android:orientation="horizontal"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:background="@color/about_page_header_grey"
+ android:layout_gravity="top"
+ android:layout_marginBottom="1dp">
+
+ <android.support.design.widget.TabLayout
+ android:id="@+id/as_detail_tablayout"
+ android:layout_width="0dp"
+ android:layout_height="match_parent"
+ android:layout_weight="1"
+ android:layout_gravity="left"
+ android:paddingLeft="12dp"
+ android:paddingRight="12dp"
+ app:tabSelectedTextColor="@color/placeholder_grey"
+ app:tabTextColor="@color/tab_text_color"
+ app:tabMode="scrollable"
+ app:tabIndicatorHeight="4dp"
+ app:tabIndicatorColor="#ff9400" />
+
+ <ImageView
+ android:layout_width="42dp"
+ android:layout_height="42dp"
+ android:padding="10dp"
+ android:src="@drawable/ab_search"
+ android:id="@+id/as_search_button"/>
+
+ <ImageView
+ android:layout_width="42dp"
+ android:layout_height="42dp"
+ android:padding="14dp"
+ android:src="@drawable/tab_close"
+ android:id="@+id/as_close_button"/>
+
+ </LinearLayout>
+
+ <android.support.v4.view.ViewPager
+ android:id="@+id/as_pager"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" />
+</LinearLayout>
\ No newline at end of file