diff --git a/Tinfoil-for-Facebook/src/main/java/com/danvelazco/fbwrapper/FbWrapper.java b/Tinfoil-for-Facebook/src/main/java/com/danvelazco/fbwrapper/FbWrapper.java
index 3a578da..fb370b2 100644
--- a/Tinfoil-for-Facebook/src/main/java/com/danvelazco/fbwrapper/FbWrapper.java
+++ b/Tinfoil-for-Facebook/src/main/java/com/danvelazco/fbwrapper/FbWrapper.java
@@ -13,9 +13,10 @@
import android.support.v4.widget.DrawerLayout;
import android.text.TextUtils;
import android.view.KeyEvent;
-import android.view.View;
import android.widget.RelativeLayout;
+
import com.danvelazco.fbwrapper.activity.BaseFacebookWebViewActivity;
+import com.danvelazco.fbwrapper.activity.DrawerFragment;
import com.danvelazco.fbwrapper.preferences.FacebookPreferences;
import com.danvelazco.fbwrapper.util.Logger;
import com.danvelazco.fbwrapper.util.OrbotHelper;
@@ -33,6 +34,8 @@ public class FbWrapper extends BaseFacebookWebViewActivity {
private DrawerLayout mDrawerLayout = null;
private RelativeLayout mWebViewContainer = null;
private String mDomainToUse = INIT_URL_MOBILE;
+ private String mDomainSuffix = INIT_URL_MOBILE_SUFFIX;
+
// Preferences stuff
private SharedPreferences mSharedPreferences = null;
@@ -49,10 +52,10 @@ protected void onActivityCreated() {
// Keep a reference of the DrawerLayout
mDrawerLayout = (DrawerLayout) findViewById(R.id.layout_main);
+ getFragmentManager().beginTransaction().replace(R.id.drawerFragment, new DrawerFragment()).commit();
mWebViewContainer = (RelativeLayout) findViewById(R.id.webview_container);
// Set the click listener interface for the buttons
- setOnClickListeners();
}
/**
@@ -110,7 +113,7 @@ protected void onWebViewInit(Bundle savedInstanceState) {
} else {
// Load the URL depending on the type of device or preference
Logger.d(LOG_TAG, "Loading the init Facebook URL");
- loadNewPage(mDomainToUse);
+ loadNewPage(mDomainToUse + mDomainSuffix);
}
}
@@ -129,30 +132,10 @@ protected void onResumeActivity() {
// If the domain changes, reload the page with the new domain
if (!mDomainToUse.equalsIgnoreCase(previousDomainUsed)) {
- loadNewPage(mDomainToUse);
+ loadNewPage(mDomainToUse + mDomainSuffix);
}
}
- /**
- * Sets the click listener on all the buttons in the activity
- */
- private void setOnClickListeners() {
- // Create a new listener
- MenuDrawerButtonListener buttonsListener = new MenuDrawerButtonListener();
-
- // Set this listener to all the buttons
- findViewById(R.id.menu_drawer_right).setOnClickListener(buttonsListener);
- findViewById(R.id.menu_item_jump_to_top).setOnClickListener(buttonsListener);
- findViewById(R.id.menu_item_refresh).setOnClickListener(buttonsListener);
- findViewById(R.id.menu_item_newsfeed).setOnClickListener(buttonsListener);
- findViewById(R.id.menu_items_notifications).setOnClickListener(buttonsListener);
- findViewById(R.id.menu_item_messages).setOnClickListener(buttonsListener);
- findViewById(R.id.menu_share_this).setOnClickListener(buttonsListener);
- findViewById(R.id.menu_preferences).setOnClickListener(buttonsListener);
- findViewById(R.id.menu_about).setOnClickListener(buttonsListener);
- findViewById(R.id.menu_kill).setOnClickListener(buttonsListener);
- }
-
/**
* Used to open the menu drawer
*/
@@ -245,22 +228,22 @@ private void loadPreferences() {
// Force or detect the site mode to load
if (mode.equalsIgnoreCase(FacebookPreferences.SITE_MODE_MOBILE)) {
// Force the webview config to mobile
- setupFacebookWebViewConfig(true, true, false, false, false);
+ setupFacebookWebViewConfig(MOBILE);
} else if (mode.equalsIgnoreCase(FacebookPreferences.SITE_MODE_DESKTOP)) {
// Force the webview config to desktop mode
- setupFacebookWebViewConfig(true, false, false, false, false);
+ setupFacebookWebViewConfig(DESKTOP);
} else if (mode.equalsIgnoreCase(FacebookPreferences.SITE_MODE_ZERO)) {
// Force the webview config to zero mode
- setupFacebookWebViewConfig(false, true, false, true, false);
+ setupFacebookWebViewConfig(ZERO);
} else if (mode.equalsIgnoreCase(FacebookPreferences.SITE_MODE_BASIC)) {
// Force the webview to load the Basic HTML Mobile site
- setupFacebookWebViewConfig(true, true, true, false, false);
+ setupFacebookWebViewConfig(BASIC);
} else if (mode.equalsIgnoreCase(FacebookPreferences.SITE_MODE_ONION)) {
// Force the webview to load Facebook via Tor (onion network)
- setupFacebookWebViewConfig(true, true, false, false, true);
+ setupFacebookWebViewConfig(ONION);
} else {
// Do not force, allow us to auto-detect what mode to use
- setupFacebookWebViewConfig(false, true, false, false, false);
+
}
// If we haven't shown the new menu drawer to the user, auto open it
@@ -278,35 +261,39 @@ private void loadPreferences() {
/**
* Configure this {@link com.danvelazco.fbwrapper.webview.FacebookWebView}
* with the appropriate preferences depending on the device configuration.
- * Use the 'force' flag to force the configuration to either mobile or desktop.
*
- * @param force {@link boolean}
- * whether to force the configuration or not,
- * if false the 'mobile' flag will be ignored
- * @param mobile {@link boolean}
- * whether to use the mobile or desktop site.
- * @param facebookZero {@link boolean}
- * whether or not to use Facebook Zero
+ * @param domainType {@link int} Which URL type we are using.
*/
- // TODO: time to fix this mess
- private void setupFacebookWebViewConfig(boolean force, boolean mobile, boolean facebookBasic,
- boolean facebookZero, boolean facebookOnion) {
- if (force && !mobile) {
- // Force the desktop site to load
- mDomainToUse = INIT_URL_DESKTOP;
- } else if (facebookZero) {
- // If Facebook zero is set, use that
- mDomainToUse = INIT_URL_FACEBOOK_ZERO;
- } else if (facebookOnion) {
- // If the Onion domain is set, use that
- mDomainToUse = INIT_URL_FACEBOOK_ONION;
- } else {
- // Otherwise, just load the mobile site for all devices
- mDomainToUse = INIT_URL_MOBILE;
+ private void setupFacebookWebViewConfig(int domainType) {
+ switch (domainType) {
+ case DESKTOP:
+ // Force the desktop site to load
+ mDomainToUse = INIT_URL_DESKTOP;
+ mDomainSuffix = INIT_URL_NORMAL_SUFFIX;
+ break;
+ case ZERO:
+ // If Facebook zero is set, use that
+ mDomainToUse = INIT_URL_FACEBOOK_ZERO;
+ mDomainSuffix = INIT_URL_NORMAL_SUFFIX;
+ break;
+ case ONION:
+ // If the Onion domain is set, use that
+ mDomainToUse = INIT_URL_FACEBOOK_ONION;
+ mDomainSuffix = INIT_URL_NORMAL_SUFFIX;
+ break;
+ case BASIC:
+ // Found a URL that can replace the Firefox for Android UA
+ mDomainToUse = INIT_URL_FACEBOOK_BASIC;
+ mDomainSuffix = INIT_URL_NORMAL_SUFFIX;
+ break;
+ case MOBILE:
+ mDomainSuffix = INIT_URL_MOBILE_SUFFIX;
+ // Otherwise, just load the mobile site for all devices
+ break;
}
// Set the user agent depending on config
- setUserAgent(force, mobile, facebookBasic);
+ setUserAgent(domainType);
}
/**
@@ -335,48 +322,41 @@ private boolean isDeviceTablet() {
return isTablet;
}
- /**
- * Menu drawer button listener interface
- */
- private class MenuDrawerButtonListener implements View.OnClickListener {
- /**
- * {@inheritDoc}
- */
- @Override
- public void onClick(View v) {
- switch (v.getId()) {
- case R.id.menu_item_jump_to_top:
+ public void drawerClick(int position) {
+ switch (position) {
+ case 0:
jumpToTop();
break;
- case R.id.menu_item_refresh:
+ case 1:
refreshCurrentPage();
break;
- case R.id.menu_item_newsfeed:
- loadNewPage(mDomainToUse + "?sk=h_chr");
+ case 2:
+ loadNewPage(mDomainToUse + mDomainSuffix);
break;
- case R.id.menu_items_notifications:
+ case 3:
loadNewPage(mDomainToUse + URL_PAGE_NOTIFICATIONS);
break;
- case R.id.menu_item_messages:
+ case 4:
loadNewPage(mDomainToUse + URL_PAGE_MESSAGES);
break;
- case R.id.menu_share_this:
+ case 5:
shareCurrentPage();
break;
- case R.id.menu_preferences:
+ case 6:
startActivity(new Intent(FbWrapper.this, FacebookPreferences.class));
+
break;
- case R.id.menu_about:
+ case 7:
showAboutAlert();
break;
- case R.id.menu_kill:
+ case 8:
mWebViewContainer.removeView(mWebView);
destroyWebView();
finish();
break;
}
closeMenuDrawer();
- }
+
}
/**
@@ -384,6 +364,8 @@ public void onClick(View v) {
*/
private void showAboutAlert() {
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
+
+
alertDialog.setTitle(getString(R.string.menu_about));
alertDialog.setMessage(getString(R.string.txt_about));
alertDialog.setIcon(R.drawable.ic_launcher);
@@ -417,4 +399,5 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {
return super.onKeyDown(keyCode, event);
}
+
}
diff --git a/Tinfoil-for-Facebook/src/main/java/com/danvelazco/fbwrapper/activity/BaseFacebookWebViewActivity.java b/Tinfoil-for-Facebook/src/main/java/com/danvelazco/fbwrapper/activity/BaseFacebookWebViewActivity.java
index ca7ca0c..4be19a6 100644
--- a/Tinfoil-for-Facebook/src/main/java/com/danvelazco/fbwrapper/activity/BaseFacebookWebViewActivity.java
+++ b/Tinfoil-for-Facebook/src/main/java/com/danvelazco/fbwrapper/activity/BaseFacebookWebViewActivity.java
@@ -65,7 +65,7 @@
* Base activity that uses a {@link FacebookWebView} to load the Facebook
* site in different formats. Here we can implement all the boilerplate code
* that has to do with loading the activity as well as lifecycle events.
- *
* See {@link #onActivityCreated()}
* See {@link #onWebViewInit(android.os.Bundle)}
* See {@link #onResumeActivity()}
@@ -82,9 +82,18 @@ public abstract class BaseFacebookWebViewActivity extends Activity implements
protected final static String INIT_URL_MOBILE = "https://m.facebook.com";
protected final static String INIT_URL_DESKTOP = "https://www.facebook.com";
protected final static String INIT_URL_FACEBOOK_ZERO = "https://0.facebook.com";
+ protected final static String INIT_URL_FACEBOOK_BASIC = "https://mbasic.facebook.com/";
protected final static String INIT_URL_FACEBOOK_ONION = "https://facebookcorewwwi.onion";
+ // Because Facebook's new mobile site needs the /home.php to properly force Most Recent.
+ protected final static String INIT_URL_NORMAL_SUFFIX = "?sk=h_chr";
+ protected final static String INIT_URL_MOBILE_SUFFIX = "/home.php?sk=h_chr";
protected final static String URL_PAGE_NOTIFICATIONS = "/notifications.php";
protected final static String URL_PAGE_MESSAGES = "/messages";
+ protected final static int ZERO = 0;
+ protected final static int BASIC = 1;
+ protected final static int DESKTOP = 2;
+ protected final static int MOBILE = 3;
+ protected final static int ONION = 4;
// URL for Sharing Links
// u = url & t = title
@@ -99,8 +108,6 @@ public abstract class BaseFacebookWebViewActivity extends Activity implements
// Mobile user agent (Mobile user agent from a Google Nexus 5 running Android 4.4.2
protected static final String USER_AGENT_MOBILE = "Mozilla/5.0 (Linux; Android 5.0; Nexus 5 Build/LRX21O) " +
"AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/37.0.0.0 Mobile Safari/537.36";
- // Firefox for Android user agent, it brings up a basic version of the site. Halfway between touch site and zero site.
- protected static final String USER_AGENT_BASIC = "Mozilla/5.0 (Android; Mobile; rv:13.0) Gecko/13.0 Firefox/13.0";
// Members
protected ConnectivityManager mConnectivityManager = null;
@@ -309,31 +316,24 @@ protected void restoreWebView(Bundle inState) {
}
/**
- * Set the browser user agent to be used. If the user agent should be forced,
- * make sure the 'force' param is set to true, otherwise the devices' default
- * user agent will be used.
+ * Set the browser user agent to be used.
*
- * @param force {@link boolean}
- * true if we should force a custom user agent, false if not.
- * Note, if this flag is false the default user agent will be
- * used while disregarding the mobile {@link boolean} parameter
- * @param mobile {@link boolean}
- * true if we should use a custom user agent for mobile devices,
- * false if not.
- */
- protected void setUserAgent(boolean force, boolean mobile, boolean facebookBasic) {
- if (force && mobile && !facebookBasic) {
+ * @param type {@link int} Which user agent to use.
+ *
+ */
+ protected void setUserAgent(int type) {
+ if (type == MOBILE) {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN_MR2) {
mWebSettings.setUserAgentString(USER_AGENT_MOBILE_OLD);
} else {
mWebSettings.setUserAgentString(USER_AGENT_MOBILE);
}
- } else if (force && !mobile && !facebookBasic) {
+ } else if (type == DESKTOP) {
mWebSettings.setUserAgentString(USER_AGENT_DESKTOP);
- } else if (force && mobile && facebookBasic) {
- mWebSettings.setUserAgentString(USER_AGENT_BASIC);
- } else {
- mWebSettings.setUserAgentString(null);
+ }
+ // Basic, Onion, Auto and Zero do not need a user agent, so use the system default.
+ else {
+ mWebSettings.setUserAgentString(WebSettings.getDefaultUserAgent(this));
}
}
diff --git a/Tinfoil-for-Facebook/src/main/java/com/danvelazco/fbwrapper/activity/DrawerFragment.java b/Tinfoil-for-Facebook/src/main/java/com/danvelazco/fbwrapper/activity/DrawerFragment.java
new file mode 100644
index 0000000..64e7161
--- /dev/null
+++ b/Tinfoil-for-Facebook/src/main/java/com/danvelazco/fbwrapper/activity/DrawerFragment.java
@@ -0,0 +1,57 @@
+package com.danvelazco.fbwrapper.activity;
+
+import android.app.ListFragment;
+import android.content.res.TypedArray;
+import android.graphics.drawable.ColorDrawable;
+import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ListView;
+
+import com.danvelazco.fbwrapper.FbWrapper;
+import com.danvelazco.fbwrapper.R;
+import com.danvelazco.fbwrapper.util.MySimpleArrayAdapter;
+
+/**
+ * A ListFragment that replaces the million OnClickListeners previously used in the Drawer.
+ */
+public class DrawerFragment extends ListFragment {
+ private String[] mPlanetTitles;
+ private int[] mIcons;
+
+
+
+ public DrawerFragment() {}
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ inflater.inflate(R.layout.drawer_fragment, container, false);
+
+ mPlanetTitles = getResources().getStringArray(R.array.drawer_items);
+ TypedArray ar = getResources().obtainTypedArray(R.array.drawer_item_icons);
+ int len = ar.length();
+ mIcons = new int[len];
+ for (int i = 0; i < len; i++)
+ mIcons[i] = ar.getResourceId(i, 0);
+
+ ar.recycle();
+ // Set the adapter for the list view
+ setListAdapter(new MySimpleArrayAdapter(getActivity(), mPlanetTitles, mIcons));
+ // Set the list's click listener
+
+ return super.onCreateView(inflater, container, savedInstanceState);
+ }
+ @Override
+ public void onViewCreated(View v, Bundle savedInstanceState) {
+ super.onViewCreated(v, savedInstanceState);
+ getListView().setDividerHeight(0);
+ getListView().setDivider(new ColorDrawable(android.R.color.transparent));
+ }
+ @Override
+ public void onListItemClick(ListView l, View view, int position, long id) {
+ ((FbWrapper)getActivity()).drawerClick(position);
+ }
+
+}
diff --git a/Tinfoil-for-Facebook/src/main/java/com/danvelazco/fbwrapper/util/MySimpleArrayAdapter.java b/Tinfoil-for-Facebook/src/main/java/com/danvelazco/fbwrapper/util/MySimpleArrayAdapter.java
new file mode 100644
index 0000000..4089fea
--- /dev/null
+++ b/Tinfoil-for-Facebook/src/main/java/com/danvelazco/fbwrapper/util/MySimpleArrayAdapter.java
@@ -0,0 +1,37 @@
+package com.danvelazco.fbwrapper.util;
+
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import com.danvelazco.fbwrapper.R;
+
+public class MySimpleArrayAdapter extends ArrayAdapter
- * Extends {@link android.webkit.WebViewClient}.
+ * FacebookWebViewClient.
+ * Extends {@link android.webkit.WebViewClient}.
* Used by {@link FacebookWebView}.
*/
public class FacebookWebViewClient extends WebViewClient {
+ private String TAG = getClass().getSimpleName();
+
// Members
private WebViewClientListener mListener = null;
private boolean mAllowAnyUrl = false;
@@ -68,10 +70,10 @@ public void setAllowAnyDomain(boolean allow) {
*/
@Override
public void onReceivedError(WebView view, int errorCod, String description, String failingUrl) {
- Logger.e(getClass().getSimpleName(), "This WebView has received an error while trying to load:");
- Logger.e(getClass().getSimpleName(), "\tError code: " + errorCod);
- Logger.e(getClass().getSimpleName(), "\tDescription: " + description);
- Logger.e(getClass().getSimpleName(), "\tFailed URL: " + failingUrl);
+ Logger.e(TAG, "This WebView has received an error while trying to load:");
+ Logger.e(TAG, "\tError code: " + errorCod);
+ Logger.e(TAG, "\tDescription: " + description);
+ Logger.e(TAG, "\tFailed URL: " + failingUrl);
}
/**
@@ -97,31 +99,31 @@ public boolean shouldOverrideKeyEvent(WebView view, KeyEvent event) {
*/
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
- Logger.d(getClass().getSimpleName(), "shouldOverrideUrlLoading? " + url);
+ Logger.d(TAG, "shouldOverrideUrlLoading? " + url);
// Do not override any type of loading if we can load any URL
if (mAllowAnyUrl) {
- Logger.d(getClass().getSimpleName(), "The user is allowing us to open any URL in this WebView, let it load.");
+ Logger.d(TAG, "The user is allowing us to open any URL in this WebView, let it load.");
return false;
}
// Avoid NPEs when clicking on weird blank links
if (url.equals("about:blank")) {
- Logger.d(getClass().getSimpleName(), "Blank page, let it load");
+ Logger.d(TAG, "Blank page, let it load");
return false;
}
// Get the URL's domain name
String domain = Uri.parse(url).getHost();
- Logger.d(getClass().getSimpleName(), "Checking URL: " + url);
- Logger.d(getClass().getSimpleName(), "\tDomain: " + domain);
+ Logger.d(TAG, "Checking URL: " + url);
+ Logger.d(TAG, "\tDomain: " + domain);
if (domain != null) {
// Let this WebView open the URL
// TODO: Check the proper domain names that facebook uses or find another way
if (domain.contains("facebook") || domain.contains("fb")) {
- Logger.d(getClass().getSimpleName(), "This URL should be loaded internally. Let it load.");
+ Logger.d(TAG, "This URL should be loaded internally. Let it load.");
view.loadUrl(url);
return false;
}
@@ -129,7 +131,7 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) {
// Otherwise, fire the listener to open the URL by
// any app that can handle it
- Logger.d(getClass().getSimpleName(), "This URL should be loaded by a 3rd party. Override.");
+ Logger.d(TAG, "This URL should be loaded by a 3rd party. Override.");
fireOpenExternalSiteListener(url);
return true;
diff --git a/Tinfoil-for-Facebook/src/main/res/layout/drawer_fragment.xml b/Tinfoil-for-Facebook/src/main/res/layout/drawer_fragment.xml
new file mode 100644
index 0000000..5d9ab33
--- /dev/null
+++ b/Tinfoil-for-Facebook/src/main/res/layout/drawer_fragment.xml
@@ -0,0 +1,10 @@
+
+