From 19dcb8ce70834fa94d65b8ddcd24b3bd1e2ba353 Mon Sep 17 00:00:00 2001 From: t61p Date: Thu, 4 May 2017 19:31:47 +0900 Subject: [PATCH 01/56] Japanese translation update --- app/src/main/res/values-ja/strings.xml | 252 ++++++++++++++++--------- 1 file changed, 164 insertions(+), 88 deletions(-) diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index ebb59f5..a19ef8d 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -20,47 +20,50 @@ 履歴 ブックマーク ブックマークに追加 - リンクをコピー + ページの URL をコピー 進む 設定 - 位置情報 + 位置情報の使用を許可する パスワードを記憶する ユーザーエージェント - Adobe Flash - スタートページ + Adobe Flash を有効にする + ホームページ 全画面モード - JavaScript - ダウンロード先のフォルダ - 高度な設定 + JavaScript を有効にする + ダウンロードフォルダ + 詳細 Apache License 2.0 - アプリケーションのバージョン + アプリのバージョン 終了時にキャッシュを消去する - 文字を右端で折り返す + テキストを右端で折り返す 画像を読み込まない - 新しいタブでページを開くことを許可する - Cookiesを有効にする - 他のブラウザからブックマークを読み込む + サイトが新しいタブを開くことを許可する + Cookie を有効にする + 他のブラウザからブックマークをインポートする 文字サイズ 推奨 検索エンジン 検索 - ワイドビューモードを使用する - オーバービューモードでページを読み込む - 開始時に前のタブを修復する - 読み込み可能なブラウザはありません - 読み込み可能なブラウザがあります - ブラウズ中ステータスバーを非表示にする - Cookiesを消去する - Clear Browser History + Wide view port を使用する + Overview mode でページを読み込む + 前回終了時のタブをアプリ起動時に復元する + サポートしているブラウザ + 標準ブラウザ + 標準ブラウザが見つかりません + サポートしている標準ブラウザが見つかりました + ステータスバーを非表示にする + Cookie を消去する + 履歴を消去する この画像をどうしますか? ダウンロード 開く このリンクをどうしますか? - このページを共有 + このページを共有します + この履歴項目をどうしますか? このブックマークをどうしますか? - 消去 - 空のページ - 標準 + 削除 + 空白ページ + デフォルト デスクトップ モバイル カスタム @@ -69,15 +72,15 @@ このファイルをダウンロードしますか? キャンセル 警告 - Adobe Flash Playerをインストールしてください + Adobe Flash Player が見つかりません\nFlash Player をインストールしてください ユーザーエージェント - ダウンロード先 - カスタムスタートページ - Webpage + ダウンロードフォルダ + カスタムホームページ + ウェブページ 履歴を消去する - Cookiesを消去する + Cookie を消去する すべての履歴を消去しますか? - すべてのCookiesを消去しますか? + すべての Cookie を消去しますか? はい いいえ 文字サイズ @@ -87,96 +90,169 @@ 最小 エラー - どのブラウザからもブックマークが読み込めませんでした - 名前 + ブックマークをインポートするブラウザが見つかりません + タイトル URL ブックマークを編集する 編集 新しいシークレットタブ - 標準 + デフォルト 戻る - ページ内検索 - Starting download\u2026 - \"http\" や \"https\" から始まるURLのみダウンロードできます - SDカードがありません - ファイルをダウンロードするにはUSBストレージが必要です - USBストレージが利用不可です - ストレージがビジー状態です。ダウンロードするには、ステータスバーからUSB接続を変更してください。 - シークレットタブでCookiesを有効にする + ページ内を検索 + ダウンロードを開始します\u2026 + \"http\" または \"https\" で始まる URL のみダウンロードできます + 無効な URL です。ダウンロードできません + 指定したフォルダにダウンロードできません + SD カードがありません + ファイルをダウンロードするには USB ストレージが必要です + USB ストレージが使用できません + ストレージがビジー状態です。ダウンロードするには、ステータスバーの \"USB ストレージをオフにする\" をタップしてください + シークレットタブで Cookie を有効にする Adobe Flash - マニュアル + 手動 自動 - Contact Me - twitter.com/ACRDevelopment + 問い合わせ先 + twitter.com/RestainoAnthony キャッシュを消去する キャッシュを消去しました - ブックマークを読み込みました + ブックマークをインポートしました 履歴を消去しました - Cookiesを消去しました + Cookie を消去しました これ以上タブは開けません - クリップボードにテキストをコピーしました - クリップボードにリンクをコピーしました - カスタムURL - Local file has been blocked from loading - オープンソースライセンス - Search for - 広告ブロック - フォームの再送 - データを再送しますか? - \n位置情報の提供を許可しますか? + テキストをクリップボードにコピーしました + リンクをクリップボードにコピーしました + カスタム URL + ファイルを読み込めませんでした + オープンソース ライセンス + 検索 : + 広告をブロックする + このサイトへの接続は安全ではありません:\n%1$s\nそれでも続行しますか? + 証明書の日付が無効です + 証明書の期限が切れました + 証明書のドメインとサイトのドメインが一致しません + 証明書は無効です + 証明書はまだ有効ではありません + 証明書が信頼できません + フォームの再送信 + データを再送信しますか? + \n位置情報の使用を要求しています 許可する 許可しない サインイン ユーザー名 パスワード - 検索候補を表示する - Powered by Google - Orbotがインストールされています。Torを使用しますか? - Torでプロキシを有効にするにはOrbotをインストールしてください + 検索候補表示 + Google を使用する + DuckDuckGo を使用する + 検索候補を表示しない + HTTP プロキシ + + 使用しない + Orbot + I2P + 手動 + + 手動プロキシ + ホスト: + ポート: + Orbot はインストール済みです。Tor を使用しますか? + I2P はインストール済みです。I2P を使用しますか? + プロキシとして Tor を使用にするには Orbot をインストールしてください + I2P が動作していません + I2P トンネルの使用準備が整っていません はい いいえ - 終了時にCookiesを消去する + 終了時に Cookie を消去する 終了時に履歴を消去する - 規定 + デフォルト カスタム - Untitled + タイトルなし Mozilla Public License v. 2.0 Freeware Android Open Source Project hpHosts Ad Server List - 古いタブをもう1度開く + 閉じたタブを元に戻す レンダリングモード - 反転 + 色の反転 グレースケール - 反転・グレースケール + 反転グレースケール + 高コントラスト 通常 - Googleと履歴を同期する - File Chooser + Google と履歴を同期する + ファイルの選択 NetCipher GNU Lesser General Public License - バックアップにブックマークを書き出す - バックアップからブックマークを読み込む - ブックマークの書き出し先 - ブックマーク設定 - ファイルからブックマークを読み込めませんでした + ブックマークをエクスポートする + ブックマークをインポートする + ブックマークをエクスポートしました + ブックマーク + ブックマークのインポートに失敗しました ファイルを選択してください - 一般設定 - 表示設定 - 個人設定 - About - バージョン・開発者・ライセンスについての詳細 + 全般 + 表示 + プライバシー + このアプリについて + バージョン, 開発者, ライセンスなどの詳細 + 現在のタブを閉じる 全てのタブを閉じる - タブを閉じる + 他のタブを閉じる + サードパーティ Cookie を拒否する カラーモードを有効にする - フォルダ - リネーム - Webストレージをクリア - 終了時にWebストレージをクリア - フォルダ名 - 色を反転する リーダーモード + 読み込み中… + このページから何も読み出せませんでした + Snacktory + jsoup: Java HTML Parser + MIT License + URL 欄の表示内容 + テキストエンコーディング + + ドメイン名 (デフォルト) + URL + タイトル + + 色を反転する + ダーク タブ - サードパーティCookieを無効にする - ナビゲーションドロワでタブを表示する - URL-Boxコンテンツ + アプリのテーマ + ライト + ブラック (AMOLED) + フォルダ名 + フォルダ + 名前の変更 + フォルダ名の変更 + このフォルダをどうしますか? + Web storage を消去する + 終了時に Web storage を消去する + Web storage を消去しました + 広告ブロック用の Hosts ファイルの取得元 + 広告ブロック + タブをドロワーで表示する + ブックマークとタブのドロワーを入れ替える + \'Do Not Track\' を有効にする + Identifying Header を削除する + ホーム画面に追加 + ホーム画面にショートカットを追加しました + すべてのブックマークを削除する + + FAQ + よくある質問と回答 + + + デバッグ + LeakCanary + 変更を反映するにはアプリを再起動してください + + + 新しいタブで開く + バックグラウンドのタブで開く + シークレットタブで開く + ブックマークから削除する + ブックマークを編集する + 履歴から削除する + 画像をダウンロードする + リンクをコピーする + フォルダ名を変更する + フォルダを削除する + タブの消去 From 11cf6693af0e3628933b758b0da5643b30b880dd Mon Sep 17 00:00:00 2001 From: anthony restaino Date: Thu, 8 Jun 2017 22:25:17 -0400 Subject: [PATCH 02/56] Updating gradle version --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 1325d31..857add3 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.2' + classpath 'com.android.tools.build:gradle:2.3.3' classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.6.3' } } From daa4633d543fa57652fd70cfd92831fe9978ecb8 Mon Sep 17 00:00:00 2001 From: anthony restaino Date: Thu, 8 Jun 2017 22:39:16 -0400 Subject: [PATCH 03/56] Bumping target to API 26 --- app/build.gradle | 8 ++++---- build.gradle | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 451c6d7..bc507f7 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,12 +2,12 @@ apply plugin: 'com.android.application' apply plugin: 'com.getkeepsafe.dexcount' android { - compileSdkVersion 25 - buildToolsVersion '25.0.3' + compileSdkVersion project.targetSdkVersion + buildToolsVersion project.buildToolsVersion defaultConfig { - minSdkVersion 14 - targetSdkVersion 25 + minSdkVersion project.minSdkVersion + targetSdkVersion project.targetSdkVersion versionName project.versionName vectorDrawables.useSupportLibrary = true } diff --git a/build.gradle b/build.gradle index 857add3..8a1f3fc 100644 --- a/build.gradle +++ b/build.gradle @@ -17,8 +17,8 @@ allprojects { ext { minSdkVersion = 14 - targetSdkVersion = 25 - buildToolsVersion = '25.0.2' + targetSdkVersion = 26 + buildToolsVersion = '26.0.0' versionName = '4.5.0' versionCode_lite = 97 From 395c9673816623fb7eb7b2c782681b1ed92586ec Mon Sep 17 00:00:00 2001 From: anthony restaino Date: Thu, 8 Jun 2017 22:44:39 -0400 Subject: [PATCH 04/56] Getting rid of unnecessary casts in findViewById!!! --- .../lightning/activity/BrowserActivity.java | 6 +++--- .../lightning/activity/ReadingActivity.java | 2 +- .../lightning/activity/SettingsActivity.java | 4 ++-- .../browser/lightning/dialog/BrowserDialog.java | 6 +++--- .../lightning/dialog/LightningDialogBuilder.java | 6 +++--- .../fragment/BookmarkSettingsFragment.java | 2 +- .../lightning/fragment/BookmarksFragment.java | 4 ++-- .../fragment/DisplaySettingsFragment.java | 2 +- .../fragment/GeneralSettingsFragment.java | 6 +++--- .../browser/lightning/fragment/TabsFragment.java | 14 +++++++------- .../lightning/search/SuggestionsAdapter.java | 6 +++--- .../acr/browser/lightning/utils/IntentUtils.java | 2 -- .../browser/lightning/view/LightningWebClient.java | 6 +++--- 13 files changed, 32 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java b/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java index 56edc72..e5bf612 100644 --- a/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java +++ b/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java @@ -327,8 +327,8 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements lp.height = LayoutParams.MATCH_PARENT; customView.setLayoutParams(lp); - mArrowImage = (ImageView) customView.findViewById(R.id.arrow); - FrameLayout arrowButton = (FrameLayout) customView.findViewById(R.id.arrow_button); + mArrowImage = customView.findViewById(R.id.arrow); + FrameLayout arrowButton = customView.findViewById(R.id.arrow_button); if (mShowTabsInDrawer) { if (mArrowImage.getWidth() <= 0) { mArrowImage.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); @@ -366,7 +366,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements arrowButton.setOnClickListener(this); // create the search EditText in the ToolBar - mSearch = (SearchView) customView.findViewById(R.id.search); + mSearch = customView.findViewById(R.id.search); mSearchBackground = customView.findViewById(R.id.search_container); // initialize search background color diff --git a/app/src/main/java/acr/browser/lightning/activity/ReadingActivity.java b/app/src/main/java/acr/browser/lightning/activity/ReadingActivity.java index f554c6f..705597d 100644 --- a/app/src/main/java/acr/browser/lightning/activity/ReadingActivity.java +++ b/app/src/main/java/acr/browser/lightning/activity/ReadingActivity.java @@ -297,7 +297,7 @@ public class ReadingActivity extends AppCompatActivity { case R.id.text_size_item: View view = LayoutInflater.from(this).inflate(R.layout.dialog_seek_bar, null); - final SeekBar bar = (SeekBar) view.findViewById(R.id.text_size_seekbar); + final SeekBar bar = view.findViewById(R.id.text_size_seekbar); bar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override diff --git a/app/src/main/java/acr/browser/lightning/activity/SettingsActivity.java b/app/src/main/java/acr/browser/lightning/activity/SettingsActivity.java index 498bd06..9299cc2 100644 --- a/app/src/main/java/acr/browser/lightning/activity/SettingsActivity.java +++ b/app/src/main/java/acr/browser/lightning/activity/SettingsActivity.java @@ -29,7 +29,7 @@ public class SettingsActivity extends ThemableSettingsActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // this is a workaround for the Toolbar in PreferenceActitivty - ViewGroup root = (ViewGroup) findViewById(android.R.id.content); + ViewGroup root = findViewById(android.R.id.content); LinearLayout content = (LinearLayout) root.getChildAt(0); LinearLayout toolbarContainer = (LinearLayout) View.inflate(this, R.layout.toolbar_settings, null); @@ -38,7 +38,7 @@ public class SettingsActivity extends ThemableSettingsActivity { root.addView(toolbarContainer); // now we can set the Toolbar using AppCompatPreferenceActivity - Toolbar toolbar = (Toolbar) toolbarContainer.findViewById(R.id.toolbar); + Toolbar toolbar = toolbarContainer.findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); } diff --git a/app/src/main/java/acr/browser/lightning/dialog/BrowserDialog.java b/app/src/main/java/acr/browser/lightning/dialog/BrowserDialog.java index e6e8f28..c137a84 100644 --- a/app/src/main/java/acr/browser/lightning/dialog/BrowserDialog.java +++ b/app/src/main/java/acr/browser/lightning/dialog/BrowserDialog.java @@ -82,8 +82,8 @@ public class BrowserDialog { View layout = LayoutInflater.from(activity).inflate(R.layout.list_dialog, null); - TextView titleView = (TextView) layout.findViewById(R.id.dialog_title); - ListView listView = (ListView) layout.findViewById(R.id.dialog_list); + TextView titleView = layout.findViewById(R.id.dialog_title); + ListView listView = layout.findViewById(R.id.dialog_list); ArrayAdapter adapter = new ArrayAdapter<>(activity, android.R.layout.simple_list_item_1); @@ -136,7 +136,7 @@ public class BrowserDialog { @StringRes int action, @NonNull final EditorListener listener) { View dialogView = LayoutInflater.from(activity).inflate(R.layout.dialog_edit_text, null); - final EditText editText = (EditText) dialogView.findViewById(R.id.dialog_edit_text); + final EditText editText = dialogView.findViewById(R.id.dialog_edit_text); editText.setHint(hint); if (currentText != null) { diff --git a/app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java b/app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java index ee4c0dd..73fd6c2 100644 --- a/app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java +++ b/app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java @@ -191,12 +191,12 @@ public class LightningDialogBuilder { final AlertDialog.Builder editBookmarkDialog = new AlertDialog.Builder(activity); editBookmarkDialog.setTitle(R.string.title_edit_bookmark); final View dialogLayout = View.inflate(activity, R.layout.dialog_edit_bookmark, null); - final EditText getTitle = (EditText) dialogLayout.findViewById(R.id.bookmark_title); + final EditText getTitle = dialogLayout.findViewById(R.id.bookmark_title); getTitle.setText(item.getTitle()); - final EditText getUrl = (EditText) dialogLayout.findViewById(R.id.bookmark_url); + final EditText getUrl = dialogLayout.findViewById(R.id.bookmark_url); getUrl.setText(item.getUrl()); final AutoCompleteTextView getFolder = - (AutoCompleteTextView) dialogLayout.findViewById(R.id.bookmark_folder); + dialogLayout.findViewById(R.id.bookmark_folder); getFolder.setHint(R.string.folder); getFolder.setText(item.getFolder()); diff --git a/app/src/main/java/acr/browser/lightning/fragment/BookmarkSettingsFragment.java b/app/src/main/java/acr/browser/lightning/fragment/BookmarkSettingsFragment.java index 4e9b880..28e755e 100644 --- a/app/src/main/java/acr/browser/lightning/fragment/BookmarkSettingsFragment.java +++ b/app/src/main/java/acr/browser/lightning/fragment/BookmarkSettingsFragment.java @@ -495,7 +495,7 @@ public class BookmarkSettingsFragment extends PreferenceFragment implements Pref public void onComplete() { Activity activity = getActivity(); if (activity != null) { - String message = activity.getResources().getString(R.string.message_import); + String message = activity.getString(R.string.message_import); Utils.showSnackbar(activity, importList.size() + " " + message); } } diff --git a/app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java b/app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java index 62776b2..b447dbd 100644 --- a/app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java +++ b/app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java @@ -320,10 +320,10 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener, } private void setupNavigationButton(@NonNull View view, @IdRes int buttonId, @IdRes int imageId) { - FrameLayout frameButton = (FrameLayout) view.findViewById(buttonId); + FrameLayout frameButton = view.findViewById(buttonId); frameButton.setOnClickListener(this); frameButton.setOnLongClickListener(this); - ImageView buttonImage = (ImageView) view.findViewById(imageId); + ImageView buttonImage = view.findViewById(imageId); buttonImage.setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN); } diff --git a/app/src/main/java/acr/browser/lightning/fragment/DisplaySettingsFragment.java b/app/src/main/java/acr/browser/lightning/fragment/DisplaySettingsFragment.java index d5d796c..0cdf6d1 100644 --- a/app/src/main/java/acr/browser/lightning/fragment/DisplaySettingsFragment.java +++ b/app/src/main/java/acr/browser/lightning/fragment/DisplaySettingsFragment.java @@ -152,7 +152,7 @@ public class DisplaySettingsFragment extends LightningPreferenceFragment impleme AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); LayoutInflater inflater = getActivity().getLayoutInflater(); LinearLayout view = (LinearLayout) inflater.inflate(R.layout.dialog_seek_bar, null); - final SeekBar bar = (SeekBar) view.findViewById(R.id.text_size_seekbar); + final SeekBar bar = view.findViewById(R.id.text_size_seekbar); final TextView sample = new TextView(getActivity()); sample.setText(R.string.untitled); sample.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT)); diff --git a/app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java b/app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java index d22d112..43579f3 100644 --- a/app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java +++ b/app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java @@ -257,8 +257,8 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme private void manualProxyPicker() { View v = mActivity.getLayoutInflater().inflate(R.layout.dialog_manual_proxy, null); - final EditText eProxyHost = (EditText) v.findViewById(R.id.proxyHost); - final EditText eProxyPort = (EditText) v.findViewById(R.id.proxyPort); + final EditText eProxyHost = v.findViewById(R.id.proxyHost); + final EditText eProxyPort = v.findViewById(R.id.proxyPort); // Limit the number of characters since the port needs to be of type int // Use input filters to limite the EditText length and determine the max @@ -519,7 +519,7 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme private void downPicker() { View dialogView = LayoutInflater.from(mActivity).inflate(R.layout.dialog_edit_text, null); - final EditText getDownload = (EditText) dialogView.findViewById(R.id.dialog_edit_text); + final EditText getDownload = dialogView.findViewById(R.id.dialog_edit_text); final int errorColor = ContextCompat.getColor(mActivity, R.color.error_red); final int regularColor = ThemeUtils.getTextColor(mActivity); diff --git a/app/src/main/java/acr/browser/lightning/fragment/TabsFragment.java b/app/src/main/java/acr/browser/lightning/fragment/TabsFragment.java index 62642cf..0fed33a 100644 --- a/app/src/main/java/acr/browser/lightning/fragment/TabsFragment.java +++ b/app/src/main/java/acr/browser/lightning/fragment/TabsFragment.java @@ -130,7 +130,7 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View } else { view = inflater.inflate(R.layout.tab_strip, container, false); layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false); - ImageView newTab = (ImageView) view.findViewById(R.id.new_tab_button); + ImageView newTab = view.findViewById(R.id.new_tab_button); newTab.setColorFilter(ThemeUtils.getIconDarkThemeColor(getActivity())); newTab.setOnClickListener(new View.OnClickListener() { @Override @@ -183,7 +183,7 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View private void setupFrameLayoutButton(@NonNull final View root, @IdRes final int buttonId, @IdRes final int imageId) { final View frameButton = root.findViewById(buttonId); - final ImageView buttonImage = (ImageView) root.findViewById(imageId); + final ImageView buttonImage = root.findViewById(imageId); frameButton.setOnClickListener(this); frameButton.setOnLongClickListener(this); buttonImage.setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN); @@ -399,11 +399,11 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View public LightningViewHolder(@NonNull View view) { super(view); - txtTitle = (TextView) view.findViewById(R.id.textTab); - favicon = (ImageView) view.findViewById(R.id.faviconTab); - exit = (ImageView) view.findViewById(R.id.deleteButton); - layout = (LinearLayout) view.findViewById(R.id.tab_item_background); - exitButton = (FrameLayout) view.findViewById(R.id.deleteAction); + txtTitle = view.findViewById(R.id.textTab); + favicon = view.findViewById(R.id.faviconTab); + exit = view.findViewById(R.id.deleteButton); + layout = view.findViewById(R.id.tab_item_background); + exitButton = view.findViewById(R.id.deleteAction); exit.setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN); exitButton.setOnClickListener(this); diff --git a/app/src/main/java/acr/browser/lightning/search/SuggestionsAdapter.java b/app/src/main/java/acr/browser/lightning/search/SuggestionsAdapter.java index a14a919..2b3dd52 100644 --- a/app/src/main/java/acr/browser/lightning/search/SuggestionsAdapter.java +++ b/app/src/main/java/acr/browser/lightning/search/SuggestionsAdapter.java @@ -136,9 +136,9 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable { private static class SuggestionHolder { SuggestionHolder(@NonNull View view) { - mTitle = (TextView) view.findViewById(R.id.title); - mUrl = (TextView) view.findViewById(R.id.url); - mImage = (ImageView) view.findViewById(R.id.suggestionIcon); + mTitle = view.findViewById(R.id.title); + mUrl = view.findViewById(R.id.url); + mImage = view.findViewById(R.id.suggestionIcon); } @NonNull final ImageView mImage; diff --git a/app/src/main/java/acr/browser/lightning/utils/IntentUtils.java b/app/src/main/java/acr/browser/lightning/utils/IntentUtils.java index 7f953f4..1e36c86 100644 --- a/app/src/main/java/acr/browser/lightning/utils/IntentUtils.java +++ b/app/src/main/java/acr/browser/lightning/utils/IntentUtils.java @@ -1,14 +1,12 @@ package acr.browser.lightning.utils; import android.app.Activity; -import android.content.ActivityNotFoundException; import android.content.Intent; import android.content.IntentFilter; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.net.Uri; import android.os.Build; -import android.os.FileUriExposedException; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.util.Log; diff --git a/app/src/main/java/acr/browser/lightning/view/LightningWebClient.java b/app/src/main/java/acr/browser/lightning/view/LightningWebClient.java index 8e3f4bb..f6861fd 100644 --- a/app/src/main/java/acr/browser/lightning/view/LightningWebClient.java +++ b/app/src/main/java/acr/browser/lightning/view/LightningWebClient.java @@ -135,9 +135,9 @@ public class LightningWebClient extends WebViewClient { View dialogView = LayoutInflater.from(mActivity).inflate(R.layout.dialog_auth_request, null); - final TextView realmLabel = (TextView) dialogView.findViewById(R.id.auth_request_realm_textview); - final EditText name = (EditText) dialogView.findViewById(R.id.auth_request_username_edittext); - final EditText password = (EditText) dialogView.findViewById(R.id.auth_request_password_edittext); + final TextView realmLabel = dialogView.findViewById(R.id.auth_request_realm_textview); + final EditText name = dialogView.findViewById(R.id.auth_request_username_edittext); + final EditText password = dialogView.findViewById(R.id.auth_request_password_edittext); realmLabel.setText(mActivity.getString(R.string.label_realm, realm)); From aa7da072a3e60d8e824ed4e9a096e9b8617cfa57 Mon Sep 17 00:00:00 2001 From: anthony restaino Date: Thu, 8 Jun 2017 23:05:15 -0400 Subject: [PATCH 05/56] Updating hosts file --- app/src/LightningPlus/assets/hosts.txt | 121 +++++++++++++++++-------- 1 file changed, 85 insertions(+), 36 deletions(-) diff --git a/app/src/LightningPlus/assets/hosts.txt b/app/src/LightningPlus/assets/hosts.txt index e9d12ca..0d66715 100644 --- a/app/src/LightningPlus/assets/hosts.txt +++ b/app/src/LightningPlus/assets/hosts.txt @@ -1033,6 +1033,7 @@ 127.0.0.1 4228414.fls.doubleclick.net 127.0.0.1 4235225.fls.doubleclick.net 127.0.0.1 4236808.fls.doubleclick.net +127.0.0.1 4294919531.kt.mixmarket.biz 127.0.0.1 4299553.fls.doubleclick.net 127.0.0.1 43.6.87.194.dynamic.dol.ru 127.0.0.1 4331660.fls.doubleclick.net @@ -14754,6 +14755,7 @@ 127.0.0.1 ad1.hpg.com.br 127.0.0.1 ad1.icorp.net 127.0.0.1 ad1.kde.cz +127.0.0.1 ad1.nend.net 127.0.0.1 ad1.pamedia.com.au 127.0.0.1 ad1.paycount.com 127.0.0.1 ad1.primorye.ru @@ -15137,6 +15139,7 @@ 127.0.0.1 ad2.doublepimp.com 127.0.0.1 ad2.ero-advertising.com 127.0.0.1 ad2.firehousezone.com +127.0.0.1 ad2.fivecdm.com 127.0.0.1 ad2.hpg.com.br 127.0.0.1 ad2.ip.ro 127.0.0.1 ad2.linxcz.cz @@ -16026,6 +16029,7 @@ 127.0.0.1 addeppo.com 127.0.0.1 addesktop.com 127.0.0.1 addfreestats.com +127.0.0.1 addiliate.com 127.0.0.1 addiply.com 127.0.0.1 addltest.timesink.com 127.0.0.1 addoer.com @@ -16055,6 +16059,8 @@ 127.0.0.1 adespresso.com 127.0.0.1 adex.adchakra.net 127.0.0.1 adex.admailtiser.com +127.0.0.1 adexc.net +127.0.0.1 adexce.net 127.0.0.1 adexcite.com 127.0.0.1 adexit.com 127.0.0.1 adexit.de @@ -16197,6 +16203,7 @@ 127.0.0.1 adg.bzgint.com 127.0.0.1 adgaem.go2cloud.org 127.0.0.1 adgalax.com +127.0.0.1 adgale.com 127.0.0.1 adgardener.com 127.0.0.1 adgatemedia.com 127.0.0.1 adgatemedia.go2cloud.org @@ -16537,6 +16544,7 @@ 127.0.0.1 adrspain.go2cloud.org 127.0.0.1 adrtrklnk.com 127.0.0.1 adrunner.superstats.com +127.0.0.1 adrunnr.com 127.0.0.1 ads-03.tor.focusin.ads.targetnet.com 127.0.0.1 ads-aa.wunderground.com 127.0.0.1 ads-au.onelouder.com @@ -16838,6 +16846,7 @@ 127.0.0.1 ads.dfiles.ru 127.0.0.1 ads.dgonn.com 127.0.0.1 ads.dhakatribune.com +127.0.0.1 ads.diamonds 127.0.0.1 ads.digital-digest.com 127.0.0.1 ads.digitalhealthcare.com 127.0.0.1 ads.digitalmedianet.com @@ -17074,6 +17083,7 @@ 127.0.0.1 ads.keywordblocks.com 127.0.0.1 ads.kinobox.cz 127.0.0.1 ads.kinxxx.com +127.0.0.1 ads.kiosked.com 127.0.0.1 ads.kizu.org 127.0.0.1 ads.klixxx.com 127.0.0.1 ads.komli.com @@ -17720,6 +17730,7 @@ 127.0.0.1 ads.webmastersdirect.com 127.0.0.1 ads.webmd.com 127.0.0.1 ads.webme.com +127.0.0.1 ads.webseoanalytics.com 127.0.0.1 ads.webshots.com 127.0.0.1 ads.website-guru.com 127.0.0.1 ads.whaleads.com @@ -18294,6 +18305,7 @@ 127.0.0.1 adserver.adreactor.com 127.0.0.1 adserver.ads.com.ph 127.0.0.1 adserver.ads360.com +127.0.0.1 adserver.adtech.advertising.com 127.0.0.1 adserver.adtech.de 127.0.0.1 adserver.adtech.de.1754.9018.302br.net 127.0.0.1 adserver.adtech.de.1756.9018.302br.net @@ -18441,6 +18453,7 @@ 127.0.0.1 adserver.trellian.com 127.0.0.1 adserver.tweakers.net 127.0.0.1 adserver.ubiyoo.com +127.0.0.1 adserver.unityads.unity3d.com 127.0.0.1 adserver.veruta.com 127.0.0.1 adserver.virgin.net 127.0.0.1 adserver.weakgame.com @@ -19197,7 +19210,6 @@ 127.0.0.1 affiliatenetwork.com 127.0.0.1 affiliateprogram.keywordspy.com 127.0.0.1 affiliatequality.com -127.0.0.1 affiliates-cdn.mozilla.org 127.0.0.1 affiliates.5dimes.com 127.0.0.1 affiliates.a2hosting.com 127.0.0.1 affiliates.about.com @@ -19384,6 +19396,7 @@ 127.0.0.1 akamai.bizrate.com 127.0.0.1 akamai.smartadserver.com 127.0.0.1 akillimeyveler.reklamagaci.com +127.0.0.1 akm.playnow.guru 127.0.0.1 akmnetwork.com 127.0.0.1 aknoj.voluumtrk.com 127.0.0.1 aksb-a.akamaihd.net @@ -19731,7 +19744,6 @@ 127.0.0.1 antoinette-grabowski.us 127.0.0.1 antoinette-hanlon.us 127.0.0.1 antoinette-meisner.us -127.0.0.1 anx.mindspark.com 127.0.0.1 any.gs 127.0.0.1 anycast.fw.adsafeprotected.com 127.0.0.1 anycast.pixel.adsafeprotected.com @@ -19886,7 +19898,6 @@ 127.0.0.1 api.vungle.com 127.0.0.1 api.w3i.com 127.0.0.1 api.widgetbucks.com -127.0.0.1 api.wipmania.com 127.0.0.1 api.xdirectx.com 127.0.0.1 api.yeahmobi.com 127.0.0.1 api.yieldkit.com @@ -20187,6 +20198,7 @@ 127.0.0.1 assets.servedby-buysellads.com 127.0.0.1 assets.sharethrough.com 127.0.0.1 assets.tapad.com +127.0.0.1 assistonglobal.com 127.0.0.1 assoc-amazon.co.uk 127.0.0.1 associatedcontent.112.2o7.net 127.0.0.1 associateprograms.com @@ -20510,7 +20522,6 @@ 127.0.0.1 bam-3.nr-data.net 127.0.0.1 bam-4.nr-data.net 127.0.0.1 bam-5.nr-data.net -127.0.0.1 bam.nr-data.net 127.0.0.1 ban.krooncasino.com 127.0.0.1 ban.promotools.biz 127.0.0.1 ban3ers.ero-advertising.com @@ -21500,6 +21511,7 @@ 127.0.0.1 bbpntg3.homestead.com 127.0.0.1 bbs.duba.net 127.0.0.1 bbvj6.voluumtrk.com +127.0.0.1 bc2.fivecdm.com 127.0.0.1 bc84-88b8-96b7-6515.reporo.net 127.0.0.1 bcanalytics.bigcommerce.com 127.0.0.1 bcast.pw @@ -21706,7 +21718,6 @@ 127.0.0.1 blog.adspaces.ero-advertising.com 127.0.0.1 blog.chartboost.com 127.0.0.1 blog.data.ero-advertising.com -127.0.0.1 blog.disqus.com 127.0.0.1 blog.duba.net 127.0.0.1 blog.ero-advertising.com 127.0.0.1 blog.intext.ero-advertising.com @@ -23301,6 +23312,7 @@ 127.0.0.1 c.aol.com 127.0.0.1 c.apple.com 127.0.0.1 c.atdmt.com +127.0.0.1 c.ato.mx 127.0.0.1 c.baidu.com 127.0.0.1 c.betrad.com 127.0.0.1 c.bigmir.net @@ -23365,6 +23377,7 @@ 127.0.0.1 c.thanksearch.com 127.0.0.1 c.tracking.gamigoads.com 127.0.0.1 c.trffrcmrd.com +127.0.0.1 c.us1.dyntrk.com 127.0.0.1 c.viewsecure.net 127.0.0.1 c.vindicosuite.com 127.0.0.1 c.vrvm.com @@ -23574,7 +23587,6 @@ 127.0.0.1 campaigns.f2.com.au 127.0.0.1 campaigns.interclick.com 127.0.0.1 campaigns.rioseo.com -127.0.0.1 campaigns.services.mozilla.com 127.0.0.1 campaigntracking01.com 127.0.0.1 campf.voluumtrk.com 127.0.0.1 camsiteonline.wiredcircular.com @@ -23694,6 +23706,7 @@ 127.0.0.1 cbvtest.2cnt.net 127.0.0.1 cbx.net 127.0.0.1 cc.amazingcounters.com +127.0.0.1 cc.chango.com 127.0.0.1 cc.connextra.com 127.0.0.1 cc.zeit.de 127.0.0.1 cc03-41cf-c2ea-3a84.reporo.net @@ -23714,6 +23727,7 @@ 127.0.0.1 cdn-0.pics.dvdcdn.com 127.0.0.1 cdn-akamai.mookie1.com 127.0.0.1 cdn-ci34.actonsoftware.com +127.0.0.1 cdn-highwinds.unityads.unity3d.com 127.0.0.1 cdn-i.dmdentertainment.com 127.0.0.1 cdn-static.liverail.com 127.0.0.1 cdn-tags.mmondi.com @@ -24245,6 +24259,7 @@ 127.0.0.1 choice.demdex.net 127.0.0.1 choice.microsoft.com 127.0.0.1 choices.truste.com +127.0.0.1 chokoladsrv.net 127.0.0.1 chope-co.b.appier.net 127.0.0.1 christie-hanlon.us 127.0.0.1 christie-pearlman.us @@ -26626,6 +26641,7 @@ 127.0.0.1 d.refinedads.com 127.0.0.1 d.rmgserving.com 127.0.0.1 d.skimresources.com +127.0.0.1 d.socdm.com 127.0.0.1 d.tds.adlabs.ru 127.0.0.1 d.thanksearch.com 127.0.0.1 d.thelocal.com @@ -27259,6 +27275,7 @@ 127.0.0.1 dimpact.co.il 127.0.0.1 dina-rish.us 127.0.0.1 dinclinx.com +127.0.0.1 dintandnesin.ru 127.0.0.1 direct-revenue.com 127.0.0.1 direct-stats.com 127.0.0.1 direct-xxx-access.com @@ -27477,7 +27494,6 @@ 127.0.0.1 doubleclicks.me 127.0.0.1 doug1izaerwt3.cloudfront.net 127.0.0.1 dowlatow.justclick.ru -127.0.0.1 download-performance.com 127.0.0.1 download.akamaitools.com.edgesuite.net 127.0.0.1 download.hitbox.com 127.0.0.1 download.installnow.mobi @@ -27586,7 +27602,6 @@ 127.0.0.1 dvdbeats.com 127.0.0.1 dvnzx.voluumtrk.com 127.0.0.1 dw-eu.com.com -127.0.0.1 dw.cbsi.com 127.0.0.1 dw.cbsi.com.cn 127.0.0.1 dw.cnet.com 127.0.0.1 dw.com.com @@ -28022,6 +28037,7 @@ 127.0.0.1 enews.bfast.com 127.0.0.1 enewsletters.ziffdavisinternet.com 127.0.0.1 enfintrouver.com +127.0.0.1 engage.morespeck.com 127.0.0.1 engagebdr.com 127.0.0.1 engine.4dsply.com 127.0.0.1 engine.a.redditmedia.com @@ -28103,6 +28119,7 @@ 127.0.0.1 epxkb8zz4ssdv7b.global.ssl.fastly.net 127.0.0.1 eqads.com 127.0.0.1 eqgdx.voluumtrk.com +127.0.0.1 eqs-redserver.appspot.com 127.0.0.1 equantum.com 127.0.0.1 equitymarketingsolutions.com 127.0.0.1 eqx.smartadserver.com @@ -28258,6 +28275,7 @@ 127.0.0.1 everyfreegift.com 127.0.0.1 everyscape.com 127.0.0.1 everythingbts.com +127.0.0.1 evewronsedent.ru 127.0.0.1 evidencecleanergold.com 127.0.0.1 evisit.exeter.ac.uk 127.0.0.1 evisitcs2.com @@ -28493,6 +28511,7 @@ 127.0.0.1 feedshare.flipora.com 127.0.0.1 felitb.rightinthebox.com 127.0.0.1 femi9.voluumtrk.com +127.0.0.1 fenix-translation.com.ua 127.0.0.1 ferdy.org 127.0.0.1 fermakontenta.justclick.ru 127.0.0.1 ferrago.uk.intellitxt.com @@ -29471,7 +29490,6 @@ 127.0.0.1 geo.hyperlinksecure.com 127.0.0.1 geo.ivwbox.de 127.0.0.1 geo.metronews.ca -127.0.0.1 geo.mozilla.org 127.0.0.1 geo.mtvnn.com 127.0.0.1 geo.offermatica.com 127.0.0.1 geo.q5media.net @@ -30117,6 +30135,7 @@ 127.0.0.1 hc.rapidshare.com 127.0.0.1 hc1.humanclick.com 127.0.0.1 hc2.humanclick.com +127.0.0.1 hcharbach.de 127.0.0.1 hchrmain.112.2o7.net 127.0.0.1 hclrm.voluumtrk.com 127.0.0.1 hcu1u.voluumtrk.com @@ -30153,6 +30172,7 @@ 127.0.0.1 help.doubleclick.net 127.0.0.1 help.qualaroo.com 127.0.0.1 hernando.com +127.0.0.1 hetsedryropt.com 127.0.0.1 hexacash.com 127.0.0.1 heywire.com 127.0.0.1 heyzap.com @@ -30350,6 +30370,7 @@ 127.0.0.1 hosting2.rts.lj.doublepimp.com 127.0.0.1 hosting4.rts.fling.doublepimp.com 127.0.0.1 hostlnks.com +127.0.0.1 hostpedia.ro 127.0.0.1 hostpost4.xyz 127.0.0.1 hot50.net 127.0.0.1 hotdatinglist.com @@ -30366,6 +30387,7 @@ 127.0.0.1 housead.umeng.com 127.0.0.1 howaboutwe.go2cloud.org 127.0.0.1 howardchui.us.intellitxt.com +127.0.0.1 howrowthettof.com 127.0.0.1 hoz01.voluumtrk.com 127.0.0.1 hpglobal.112.2o7.net 127.0.0.1 hphqglobal.112.2o7.net @@ -30486,13 +30508,16 @@ 127.0.0.1 i.n.jwpltx.com 127.0.0.1 i.nuseek.com 127.0.0.1 i.offerx.co.uk +127.0.0.1 i.playnow.guru 127.0.0.1 i.plug.it 127.0.0.1 i.po.st 127.0.0.1 i.psa-ads.openx.com 127.0.0.1 i.r1-cdn.net 127.0.0.1 i.sahcdn.com 127.0.0.1 i.sbitinbsjs.info +127.0.0.1 i.serves.live 127.0.0.1 i.simpli.fi +127.0.0.1 i.socdm.com 127.0.0.1 i.tapit.com 127.0.0.1 i.tfag.de 127.0.0.1 i.theuseful.com @@ -30659,7 +30684,6 @@ 127.0.0.1 iframe.mediaplazza.com 127.0.0.1 iframe.sponsorpay.com 127.0.0.1 iframe.travel.yahoo.com -127.0.0.1 iframehost.com 127.0.0.1 iframes.hustler.com 127.0.0.1 iframesrccdn1.adexprt.com 127.0.0.1 iframesrccdn2.adexprt.com @@ -30846,7 +30870,6 @@ 127.0.0.1 imaginemedia.net 127.0.0.1 imap.linkshare.com 127.0.0.1 imatmobile.com -127.0.0.1 imb.mobitkr.com 127.0.0.1 imedia.co.il 127.0.0.1 imeds.ero-advertising.com 127.0.0.1 imeseonetwork.go2cloud.org @@ -30945,6 +30968,7 @@ 127.0.0.1 img04.webtrekk.net 127.0.0.1 img05.webtrekk.net 127.0.0.1 img06.webtrekk.net +127.0.0.1 img1.nend.net 127.0.0.1 img1.webring.com 127.0.0.1 img2.freeze.com 127.0.0.1 img2.paipaiimg.com @@ -31314,7 +31338,6 @@ 127.0.0.1 j.adlooxtracking.com 127.0.0.1 j.clickdensity.com 127.0.0.1 j.kissinsights.com -127.0.0.1 j.mp 127.0.0.1 j.ophan.co.uk 127.0.0.1 j.rvttrack.com 127.0.0.1 j.sahcdn.com @@ -33074,6 +33097,7 @@ 127.0.0.1 mediauk.247realmedia.com 127.0.0.1 mediavisor.doubleclick.com 127.0.0.1 mediavisor.doubleclick.net +127.0.0.1 mediawhirl.net 127.0.0.1 mediciinternet.go2cloud.org 127.0.0.1 medicinenet.us.intellitxt.com 127.0.0.1 medio.com @@ -33159,7 +33183,6 @@ 127.0.0.1 metrics.loomia.com 127.0.0.1 metrics.mcafee.com 127.0.0.1 metrics.mmailhost.com -127.0.0.1 metrics.mozilla.com 127.0.0.1 metrics.nexgen.neustar.biz 127.0.0.1 metrics.payback.de 127.0.0.1 metrics.premiereradio.net @@ -33609,7 +33632,6 @@ 127.0.0.1 my.applifier.com 127.0.0.1 my.blueadvertise.com 127.0.0.1 my.hellobar.com -127.0.0.1 my.leadpages.net 127.0.0.1 my.media-servers.net 127.0.0.1 my.mobfox.com 127.0.0.1 my.omniture.com @@ -33716,6 +33738,7 @@ 127.0.0.1 n-tv.de.intellitxt.com 127.0.0.1 n-tv.met.vgwort.de 127.0.0.1 n.bodybuilding.com +127.0.0.1 n.fclick-adnow.com 127.0.0.1 n.gemini.yahoo.com 127.0.0.1 n.ladycash.ru 127.0.0.1 n.lcads.ru @@ -33782,6 +33805,7 @@ 127.0.0.1 nancy-mosca.us 127.0.0.1 nandp.go2cloud.org 127.0.0.1 nanigans.com +127.0.0.1 nanoadexchange.com 127.0.0.1 nanostats.nanopress.it 127.0.0.1 naomi-thorn.us 127.0.0.1 napster.searchwho.com @@ -34006,6 +34030,7 @@ 127.0.0.1 nl1.ero-advertising.com 127.0.0.1 nl2.ero-advertising.com 127.0.0.1 nlbanner.nl +127.0.0.1 nlett3r.com 127.0.0.1 nlhra.voluumtrk.com 127.0.0.1 nm.netmng.com 127.0.0.1 nmaio.voluumtrk.com @@ -34144,6 +34169,7 @@ 127.0.0.1 nuera.go2cloud.org 127.0.0.1 nuggad.net 127.0.0.1 numb.hotshare.biz +127.0.0.1 nurno.com 127.0.0.1 nv.ad.naver.com 127.0.0.1 nv4n8.voluumtrk.com 127.0.0.1 nvk.realsecuredredirect.com @@ -34196,6 +34222,7 @@ 127.0.0.1 o.addthis.com 127.0.0.1 o.leadbolt.com 127.0.0.1 o.sa.aol.com +127.0.0.1 o.ss2.us 127.0.0.1 o.swisscom.ch 127.0.0.1 o.xbox.com 127.0.0.1 o.yieldsquare.com @@ -34443,6 +34470,7 @@ 127.0.0.1 onclickads.net 127.0.0.1 onclickads2.net 127.0.0.1 onclickrev.com +127.0.0.1 onclkds.com 127.0.0.1 one-time-offer.com 127.0.0.1 one.123counters.com 127.0.0.1 oneandonlynetwork.com @@ -34625,6 +34653,7 @@ 127.0.0.1 outils.acf-webmaster.net 127.0.0.1 outils.f5biz.com 127.0.0.1 outpost.real.com +127.0.0.1 output.nend.net 127.0.0.1 outsidethebeltway.us.intellitxt.com 127.0.0.1 ov.yahoo.co.jp 127.0.0.1 overpro.com @@ -34842,6 +34871,7 @@ 127.0.0.1 papayamobile.com 127.0.0.1 papi.slideme.org 127.0.0.1 paramount.go2cloud.org +127.0.0.1 pardtosinsing.ru 127.0.0.1 parenting.searchwho.com 127.0.0.1 paris.typepad.com 127.0.0.1 paritycube.go2cloud.org @@ -35247,6 +35277,7 @@ 127.0.0.1 player-services.goviral-content.com 127.0.0.1 player.piksel.com 127.0.0.1 playminigolf.com +127.0.0.1 playnow.guru 127.0.0.1 playtomic.com 127.0.0.1 plb27.voluumtrk.com 127.0.0.1 pleasedontslaymy.download @@ -35427,6 +35458,7 @@ 127.0.0.1 preciselylocate.com 127.0.0.1 precisionleads.go2cloud.org 127.0.0.1 predictad.com +127.0.0.1 predictivadvertising.com 127.0.0.1 predictivenetworks.com 127.0.0.1 preferences.truste.com 127.0.0.1 preferredpublishers.go2cloud.org @@ -35907,6 +35939,7 @@ 127.0.0.1 r.369dl.com 127.0.0.1 r.ads.zynga.com 127.0.0.1 r.adserver01.de +127.0.0.1 r.af-share.jp 127.0.0.1 r.aol.com 127.0.0.1 r.apina.biz 127.0.0.1 r.bbci.co.uk @@ -35942,7 +35975,6 @@ 127.0.0.1 r.zeroredirect1.com 127.0.0.1 r.zeroredirect2.com 127.0.0.1 r0d2x.voluumtrk.com -127.0.0.1 r1---sn-vgqsen7z.googlevideo.com 127.0.0.1 r1.ace.advertising.com 127.0.0.1 r1.beta.ace.advertising.com 127.0.0.1 r1.computerbild.de @@ -35950,27 +35982,20 @@ 127.0.0.1 r1.fmpub.net 127.0.0.1 r1.pcwelt.de 127.0.0.1 r1.plugrush.com -127.0.0.1 r1.sn-vgqsen7z.googlevideo.com 127.0.0.1 r1.zedo.com 127.0.0.1 r10.cooleremail.com 127.0.0.1 r11.cooleremail.com -127.0.0.1 r17---sn-vgqsenes.googlevideo.com -127.0.0.1 r2---sn-vgqs7n7k.googlevideo.com 127.0.0.1 r2.cooleremail.com 127.0.0.1 r2.linksynergy.com 127.0.0.1 r2.plugrush.com -127.0.0.1 r20---sn-vgqs7ne7.googlevideo.com 127.0.0.1 r20.rs6.net -127.0.0.1 r20.sn-vgqs7ne7.googlevideo.com 127.0.0.1 r2fjs.voluumtrk.com 127.0.0.1 r2jmarketing.go2cloud.org 127.0.0.1 r2v3n.voluumtrk.com 127.0.0.1 r3.cooleremail.com 127.0.0.1 r3.plugrush.com -127.0.0.1 r4---sn-vgqs7nez.googlevideo.com 127.0.0.1 r4.cooleremail.com 127.0.0.1 r4.plugrush.com -127.0.0.1 r4.sn-vgqs7nez.googlevideo.com 127.0.0.1 r4zih.voluumtrk.com 127.0.0.1 r5.cooleremail.com 127.0.0.1 r5.plugrush.com @@ -36032,6 +36057,7 @@ 127.0.0.1 rates.insureship.com 127.0.0.1 rating.openstat.com 127.0.0.1 rating.openstat.ru +127.0.0.1 ratsparropret.ru 127.0.0.1 ratx9.voluumtrk.com 127.0.0.1 ravenstonedigital.go2cloud.org 127.0.0.1 rawdinner.justclick.ru @@ -36153,6 +36179,7 @@ 127.0.0.1 redirects.timesink.com 127.0.0.1 reditions.net 127.0.0.1 redmas.com +127.0.0.1 redrct.site 127.0.0.1 redshiftleads.steele.net 127.0.0.1 redtube.yoshatia.com 127.0.0.1 reduxmedia.com @@ -36395,12 +36422,12 @@ 127.0.0.1 roia.hutchmedia.com 127.0.0.1 roiadtracker.com 127.0.0.1 roitracker.com -127.0.0.1 rollbar.com 127.0.0.1 romanticfm.2cnt.net 127.0.0.1 romview.atdmt.com.915.9004.302br.net 127.0.0.1 ronaldheft.com 127.0.0.1 roomkey.d1.sc.omtrdc.net 127.0.0.1 rootzwiki.us.intellitxt.com +127.0.0.1 ropretratspar.com 127.0.0.1 rose.ixbt.com 127.0.0.1 rosettastone.tt.omtrdc.net 127.0.0.1 rotabanner.kulichki.net @@ -36529,11 +36556,13 @@ 127.0.0.1 ryerose.net 127.0.0.1 rygpq.voluumtrk.com 127.0.0.1 ryield.jmp9.com +127.0.0.1 ryropthetsed.ru 127.0.0.1 rytj3.voluumtrk.com 127.0.0.1 rzr.tractionize.com 127.0.0.1 s-adserver.cxad.cxense.com 127.0.0.1 s-adserver.sandbox.cxad.cxense.com 127.0.0.1 s-assets.tp-cdn.com +127.0.0.1 s-cs.send.microad.jp 127.0.0.1 s-jsonp.moatads.com 127.0.0.1 s-yoolk-banner-assets.yoolk.com 127.0.0.1 s-yoolk-billboard-assets.yoolk.com @@ -36748,6 +36777,7 @@ 127.0.0.1 s90.cnzz.com 127.0.0.1 s95.research.de.com 127.0.0.1 s9kpd.voluumtrk.com +127.0.0.1 sa-receiver.sematext.com 127.0.0.1 sa.bbc.co.uk 127.0.0.1 sa.bbc.com 127.0.0.1 sa.seotoaster.com @@ -36845,7 +36875,6 @@ 127.0.0.1 script.ioam.de 127.0.0.1 script.leadboxer.com 127.0.0.1 script.opentracker.net -127.0.0.1 script.starpass.fr 127.0.0.1 script.tailsweep.com 127.0.0.1 scripts.adrcdn.com 127.0.0.1 scripts.affiliatefuture.com @@ -37042,7 +37071,6 @@ 127.0.0.1 selina-wimmer.us 127.0.0.1 sellads.eu 127.0.0.1 sem.shopexplorer.com -127.0.0.1 sematext.com 127.0.0.1 semrush.com 127.0.0.1 send.microad.jp 127.0.0.1 send4fun.com @@ -37513,8 +37541,6 @@ 127.0.0.1 sndkorea.co.kr 127.0.0.1 sndkorea.nowcdn.co.kr 127.0.0.1 snimi-sam.justclick.ru -127.0.0.1 snippets-stats.mozilla.org -127.0.0.1 snippets.mozilla.com 127.0.0.1 snonline.ivwbox.de 127.0.0.1 snowplow-collector.sugarops.com 127.0.0.1 soa.adition.com @@ -38244,6 +38270,7 @@ 127.0.0.1 stats.united-domains.de 127.0.0.1 stats.unity3d.com 127.0.0.1 stats.uswitch.com +127.0.0.1 stats.valaffiliates.com 127.0.0.1 stats.vertriebsassistent.de 127.0.0.1 stats.viddler.com 127.0.0.1 stats.virtuemart.net @@ -38491,6 +38518,7 @@ 127.0.0.1 sync.livejasmin.com 127.0.0.1 sync.mathtag.com 127.0.0.1 sync.smarttds.ru +127.0.0.1 sync.teads.tv 127.0.0.1 sync.zenoviaexchange.com 127.0.0.1 syndicate.payloadz.com 127.0.0.1 syndicate.powerofads.com @@ -38675,7 +38703,6 @@ 127.0.0.1 tag.gamecentral.hiro.tv 127.0.0.1 tag.gstat.orangeportails.net 127.0.0.1 tag.myplay.com -127.0.0.1 tag.navdmp.com 127.0.0.1 tag.reachadv.it 127.0.0.1 tag.researchnow.com 127.0.0.1 tag.shopping-feed.com @@ -38944,6 +38971,7 @@ 127.0.0.1 tfn.das.tamedia.ch 127.0.0.1 tfncdn.thaflynation.com 127.0.0.1 tfp.2ref.co +127.0.0.1 tg.socdm.com 127.0.0.1 tga.acs86.com 127.0.0.1 tga.csbew.com 127.0.0.1 tgbvfr.website @@ -38969,7 +38997,6 @@ 127.0.0.1 thehitsusa.com 127.0.0.1 theinterwebs.space 127.0.0.1 theoads.com -127.0.0.1 theoads.com. 127.0.0.1 theodosium.com 127.0.0.1 thepoint.go2cloud.org 127.0.0.1 theresa-buchman.us @@ -39040,7 +39067,6 @@ 127.0.0.1 tigerloads.com 127.0.0.1 tigertext.com 127.0.0.1 til.go2cloud.org -127.0.0.1 tiles.services.mozilla.com 127.0.0.1 tiller.co 127.0.0.1 tim-eckhoff.us 127.0.0.1 timebus2.112.2o7.net @@ -39203,6 +39229,7 @@ 127.0.0.1 tr.ilius.net 127.0.0.1 tr.interlake.net 127.0.0.1 tr.newsletter.capdecision.fr +127.0.0.1 tr.note001.com 127.0.0.1 tr.sjc.contextweb.com 127.0.0.1 tr.x-tk.net 127.0.0.1 tr1.myroitracking.com @@ -39353,6 +39380,7 @@ 127.0.0.1 track.reinvigorate.net 127.0.0.1 track.right-ads.com 127.0.0.1 track.ringcentral.com +127.0.0.1 track.scanguard.com 127.0.0.1 track.scanmyphones.com 127.0.0.1 track.scorpiointeractive.com 127.0.0.1 track.searchignite.com @@ -39478,6 +39506,7 @@ 127.0.0.1 trackicollect.ibase.fr 127.0.0.1 tracking.1moretoy.com 127.0.0.1 tracking.247search.com +127.0.0.1 tracking.4v4jfe79erfxfu8z8.com 127.0.0.1 tracking.actionads.ru 127.0.0.1 tracking.adjug.com 127.0.0.1 tracking.admarketplace.net @@ -39582,6 +39611,8 @@ 127.0.0.1 tracking.netzathleten-media.de 127.0.0.1 tracking.nuasti.com 127.0.0.1 tracking.olx-st.com +127.0.0.1 tracking.orixa-media.com +127.0.0.1 tracking.perfecttoolmedia.com 127.0.0.1 tracking.performancerevenues.com 127.0.0.1 tracking.plattformad.com 127.0.0.1 tracking.practicefusion.com @@ -39808,6 +39839,7 @@ 127.0.0.1 trk.kissmetrics.com 127.0.0.1 trk.m.libero.it 127.0.0.1 trk.mailtoward.com +127.0.0.1 trk.meacashtrk.com 127.0.0.1 trk.mobile-setting.com 127.0.0.1 trk.pswec.com 127.0.0.1 trk.rrcpm.com @@ -39817,6 +39849,7 @@ 127.0.0.1 trk.vidible.tv 127.0.0.1 trk.vindicosuite.com 127.0.0.1 trk02.gtrk.info +127.0.0.1 trk1.opanw.com 127.0.0.1 trk2it4.com 127.0.0.1 trk4.com 127.0.0.1 trkag1.com @@ -40270,6 +40303,7 @@ 127.0.0.1 uk.nedstatpro.net 127.0.0.1 uk.sitestat.com 127.0.0.1 uk.static.planet49.com +127.0.0.1 uk.websearchnow.net 127.0.0.1 uk1.siteimprove.com 127.0.0.1 ukaffiliates2.com 127.0.0.1 ukbanners.com @@ -40343,6 +40377,7 @@ 127.0.0.1 urlcash.net 127.0.0.1 urlcheck.hulu.com 127.0.0.1 urlstats.com +127.0.0.1 urlzzz.com 127.0.0.1 urx.io 127.0.0.1 us-ads.openx.net 127.0.0.1 us-east-1.profile-api.ads.linkedin.com @@ -40361,7 +40396,6 @@ 127.0.0.1 us.js.yimg.com 127.0.0.1 us.marketgid.com 127.0.0.1 us.static.planet49.com -127.0.0.1 us.upgradenow24.com 127.0.0.1 us.wa.ui-portal.com 127.0.0.1 us.webprodcdn.com 127.0.0.1 us.winninganswers.net @@ -44182,6 +44216,7 @@ 127.0.0.1 vt.adition.com 127.0.0.1 vtncmn.com 127.0.0.1 vtot.proxy.aol.com +127.0.0.1 vtrack.larvtrk.com 127.0.0.1 vtracking.in.com 127.0.0.1 vtrtl.de 127.0.0.1 vu.moatads.com @@ -45057,10 +45092,13 @@ 127.0.0.1 www.adclix.com 127.0.0.1 www.adclub.net 127.0.0.1 www.adcron.com +127.0.0.1 www.addiliate.com 127.0.0.1 www.addinto.com 127.0.0.1 www.addme.com 127.0.0.1 www.addthis.com 127.0.0.1 www.adelina-ashman.us +127.0.0.1 www.adexc.net +127.0.0.1 www.adexce.net 127.0.0.1 www.adexcite.com 127.0.0.1 www.adexm.com 127.0.0.1 www.adfest.com @@ -45094,6 +45132,7 @@ 127.0.0.1 www.admarketplace.net 127.0.0.1 www.admarvel.com 127.0.0.1 www.admaya.in +127.0.0.1 www.admaym.com 127.0.0.1 www.admedo.com 127.0.0.1 www.admeld.com 127.0.0.1 www.admestate.ru @@ -45464,6 +45503,7 @@ 127.0.0.1 www.cartonetwork.com 127.0.0.1 www.cartoonnrtwork.com 127.0.0.1 www.casalemedia.com +127.0.0.1 www.casalparis.cat 127.0.0.1 www.cash-duck.com 127.0.0.1 www.cash4files.com 127.0.0.1 www.cash4webmaster.de @@ -45499,6 +45539,7 @@ 127.0.0.1 www.checkm8.com 127.0.0.1 www.cherish-mauk.us 127.0.0.1 www.cheryl-edelstein.us +127.0.0.1 www.chokoladsrv.net 127.0.0.1 www.christi-canfield.us 127.0.0.1 www.christie-hanlon.us 127.0.0.1 www.chrystal-hollins.us @@ -45538,6 +45579,7 @@ 127.0.0.1 www.clicksrvr.co 127.0.0.1 www.clickstotrack.com 127.0.0.1 www.clicksurecpa.com +127.0.0.1 www.clicksyndicatetracking.com 127.0.0.1 www.clickterra.net 127.0.0.1 www.clicktracksolutions.com 127.0.0.1 www.clicktraffix.com @@ -45576,6 +45618,7 @@ 127.0.0.1 www.compete.com 127.0.0.1 www.competeinc.com 127.0.0.1 www.comscore.com +127.0.0.1 www.comunedeicittadini.it 127.0.0.1 www.con.vmsn.de 127.0.0.1 www.conductedresearch.com 127.0.0.1 www.connectlinking1.com @@ -45756,7 +45799,6 @@ 127.0.0.1 www.doubleclick.ne.jp 127.0.0.1 www.doubleclick.net 127.0.0.1 www.doubleclick.net.my -127.0.0.1 www.download-performance.com 127.0.0.1 www.downloadcounter.de 127.0.0.1 www.dprtb.com 127.0.0.1 www.dragonballzhomeland.com @@ -46130,7 +46172,6 @@ 127.0.0.1 www.ientry.com 127.0.0.1 www.ientrymail.com 127.0.0.1 www.ientrynetwork.net -127.0.0.1 www.iframehost.com 127.0.0.1 www.ifsmarketing.com 127.0.0.1 www.igain-mail.co.uk 127.0.0.1 www.ignitad.com @@ -46491,6 +46532,7 @@ 127.0.0.1 www.mediamind.com 127.0.0.1 www.mediaplex.com 127.0.0.1 www.mediasheva.com +127.0.0.1 www.mediawhirl.net 127.0.0.1 www.medio.com 127.0.0.1 www.meethotties.mobi 127.0.0.1 www.megacounter.de @@ -46623,6 +46665,7 @@ 127.0.0.1 www.n78adserv.com 127.0.0.1 www.n79adserv.com 127.0.0.1 www.nadia-carlyle.us +127.0.0.1 www.nanoadexchange.com 127.0.0.1 www.naomi-thorn.us 127.0.0.1 www.naturalsearchtoolresults.com 127.0.0.1 www.navteq.com @@ -46647,11 +46690,13 @@ 127.0.0.1 www.nicolette-brier.us 127.0.0.1 www.nicolette-salas.us 127.0.0.1 www.njashka.ru +127.0.0.1 www.nlett3r.com 127.0.0.1 www.nngalleries2.com 127.0.0.1 www.noelle-traxler.us 127.0.0.1 www.noelle-trotter.us 127.0.0.1 www.nonames.tk 127.0.0.1 www.noowho.com +127.0.0.1 www.nurno.com 127.0.0.1 www.nvtrak.com 127.0.0.1 www.nxsrv1.com 127.0.0.1 www.o2onbusiness.de @@ -46675,6 +46720,7 @@ 127.0.0.1 www.omtrdc.net 127.0.0.1 www.onclickads.net 127.0.0.1 www.onclickpredictiv.com +127.0.0.1 www.onclkds.com 127.0.0.1 www.oneandonlynetwork.com 127.0.0.1 www.onelouder.com 127.0.0.1 www.onestat.com @@ -46781,6 +46827,7 @@ 127.0.0.1 www.pptrk.com 127.0.0.1 www.prchecker.info 127.0.0.1 www.preciselylocate.com +127.0.0.1 www.predictivadvertising.com 127.0.0.1 www.premiumhdv.com 127.0.0.1 www.primosearch.com 127.0.0.1 www.pringotrack.com @@ -46883,7 +46930,6 @@ 127.0.0.1 www.robotreplay.com 127.0.0.1 www.roiadtracker.com 127.0.0.1 www.roitracker.com -127.0.0.1 www.rollbar.com 127.0.0.1 www.rotrk.com 127.0.0.1 www.roxyaffiliates.com 127.0.0.1 www.rsmrttracking.com @@ -46960,7 +47006,6 @@ 127.0.0.1 www.selina-krouse.us 127.0.0.1 www.selipuquoe.com 127.0.0.1 www.sellads.eu -127.0.0.1 www.sematext.com 127.0.0.1 www.semrush.com 127.0.0.1 www.send4fun.com 127.0.0.1 www.seniorttub.bid @@ -47260,6 +47305,7 @@ 127.0.0.1 www.upsellit.com 127.0.0.1 www.upv4.moatads.com 127.0.0.1 www.urlstats.com +127.0.0.1 www.urlzzz.com 127.0.0.1 www.urmediazone.com 127.0.0.1 www.urx.io 127.0.0.1 www.usabilla.com @@ -47275,6 +47321,7 @@ 127.0.0.1 www.vayavicio.com 127.0.0.1 www.vdownloadall.com 127.0.0.1 www.vectormarketing.com +127.0.0.1 www.venturead.com 127.0.0.1 www.veruta.com 127.0.0.1 www.vibrantmedia.com 127.0.0.1 www.video-loader.com @@ -47672,6 +47719,7 @@ 127.0.0.1 xiazai.duba.net 127.0.0.1 xiti.com 127.0.0.1 xl.topstat.com +127.0.0.1 xl415.com 127.0.0.1 xlite.counterpath.com 127.0.0.1 xml.adtech.fr 127.0.0.1 xml.fusionxml.com @@ -47873,6 +47921,7 @@ 127.0.0.1 zbxproxy01.con.local.vmsn.de 127.0.0.1 zc.zeroredirect1.com 127.0.0.1 zc.zeroredirect2.com +127.0.0.1 zc2.quebec-bin.com 127.0.0.1 zd.zeroredirect1.com 127.0.0.1 zdau-builder.122.2o7.net 127.0.0.1 zdau-zdnetau.122.2o7.net @@ -47974,4 +48023,4 @@ 127.0.0.1 zz.zeroredirect1.com 127.0.0.1 zzz.clickbank.net 127.0.0.1 _thums.ero-advertising.com -# Hosts: 47966 \ No newline at end of file +# Hosts: 48015 \ No newline at end of file From 6ef75b838e56249764ec4de0210271dc5c36743a Mon Sep 17 00:00:00 2001 From: anthony restaino Date: Thu, 8 Jun 2017 23:17:04 -0400 Subject: [PATCH 06/56] Updating support library --- app/build.gradle | 2 +- build.gradle | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index bc507f7..e9ae9f0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -65,7 +65,7 @@ dexcount { dependencies { // support libraries - def supportLibVersion = '25.3.1' + def supportLibVersion = '25.4.0' compile "com.android.support:palette-v7:$supportLibVersion" compile "com.android.support:appcompat-v7:$supportLibVersion" compile "com.android.support:design:$supportLibVersion" diff --git a/build.gradle b/build.gradle index 8a1f3fc..6e6a447 100644 --- a/build.gradle +++ b/build.gradle @@ -12,6 +12,7 @@ allprojects { repositories { jcenter() mavenCentral() + maven { url "https://maven.google.com" } } } From 7eac943eb144190a3ec82acb50c2c4d4b624d3e0 Mon Sep 17 00:00:00 2001 From: anthony restaino Date: Thu, 8 Jun 2017 23:17:31 -0400 Subject: [PATCH 07/56] Modifying language around disabled settings --- .../browser/lightning/fragment/GeneralSettingsFragment.java | 6 +++++- app/src/main/res/values-it/strings.xml | 2 +- app/src/main/res/values/strings.xml | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java b/app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java index 43579f3..3d11cd1 100644 --- a/app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java +++ b/app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java @@ -156,11 +156,15 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme cbAds.setEnabled(BuildConfig.FULL_VERSION); + if (!BuildConfig.FULL_VERSION) { + cbAds.setSummary(R.string.upsell_plus_version); + } + if (API < Build.VERSION_CODES.KITKAT) { cbFlash.setEnabled(true); } else { cbFlash.setEnabled(false); - cbFlash.setSummary(getResources().getString(R.string.flash_not_supported)); + cbFlash.setSummary(R.string.flash_not_supported); } cbImages.setChecked(imagesBool); diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 5683968..453b540 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -237,7 +237,7 @@ Scorciatoia aggiunta Cancella tutti i segnalibri Inverti pannello segnalibri con schede - Flash Player non è supportato dal tuo sistema! + Flash Player non è supportato dal tuo sistema FAQ Domande più frequenti diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index cda38c4..bfee5cf 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -227,7 +227,8 @@ Add to home screen Shortcut added to home screen Delete all bookmarks - Flash Player is not supported by your system! + Flash Player is not supported by your system + Upgrade to Lightning Plus to block ads FAQ Frequently asked questions From 1f206d3db8abe54867f4795a84fbf53fa056ca33 Mon Sep 17 00:00:00 2001 From: anthony restaino Date: Thu, 8 Jun 2017 23:21:48 -0400 Subject: [PATCH 08/56] Updating travis build components --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index d0075eb..f575367 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,8 +5,8 @@ jdk: android: components: - tools - - build-tools-25.0.3 - - android-25 + - build-tools-26.0.0 + - android-26 - extra-android-support - extra-android-m2repository licenses: From a02ac29057b32c7aeddbaa3e15270057d80c00fe Mon Sep 17 00:00:00 2001 From: anthony restaino Date: Fri, 9 Jun 2017 20:37:41 -0400 Subject: [PATCH 09/56] Switching HistoryDatabase to implement reactive interface --- .../lightning/activity/BrowserActivity.java | 6 +- .../acr/browser/lightning/app/AppModule.java | 13 +- .../lightning/constant/HistoryPage.java | 3 +- .../database/history/HistoryDatabase.java | 163 +++++++++++------- .../database/history/HistoryModel.java | 80 ++------- .../dialog/LightningDialogBuilder.java | 3 +- .../fragment/PrivacySettingsFragment.java | 8 +- .../lightning/search/SuggestionsAdapter.java | 10 +- .../acr/browser/lightning/utils/WebUtils.java | 4 +- 9 files changed, 148 insertions(+), 142 deletions(-) diff --git a/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java b/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java index e5bf612..ff28dff 100644 --- a/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java +++ b/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java @@ -185,6 +185,8 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements // The singleton BookmarkManager @Inject BookmarkModel mBookmarkManager; + @Inject HistoryModel mHistoryModel; + @Inject LightningDialogBuilder mBookmarksDialogBuilder; private TabsManager mTabsManager; @@ -1250,7 +1252,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements Log.d(TAG, "Cache Cleared"); } if (mPreferences.getClearHistoryExitEnabled() && !isIncognito()) { - WebUtils.clearHistory(this); + WebUtils.clearHistory(this, mHistoryModel); Log.d(TAG, "History Cleared"); } if (mPreferences.getClearCookiesExitEnabled() && !isIncognito()) { @@ -1584,7 +1586,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements return; } - HistoryModel.visitHistoryItem(url, title) + mHistoryModel.visitHistoryItem(url, title) .subscribeOn(Schedulers.io()) .subscribe(new CompletableOnSubscribe() { @Override diff --git a/app/src/main/java/acr/browser/lightning/app/AppModule.java b/app/src/main/java/acr/browser/lightning/app/AppModule.java index 400d783..9ae607a 100644 --- a/app/src/main/java/acr/browser/lightning/app/AppModule.java +++ b/app/src/main/java/acr/browser/lightning/app/AppModule.java @@ -12,6 +12,8 @@ import acr.browser.lightning.database.bookmark.BookmarkDatabase; import acr.browser.lightning.database.bookmark.BookmarkModel; import acr.browser.lightning.database.downloads.DownloadsDatabase; import acr.browser.lightning.database.downloads.DownloadsModel; +import acr.browser.lightning.database.history.HistoryDatabase; +import acr.browser.lightning.database.history.HistoryModel; import dagger.Module; import dagger.Provides; @@ -36,17 +38,24 @@ public class AppModule { @NonNull @Provides @Singleton - public BookmarkModel provideBookmarkMode() { + public BookmarkModel provideBookmarkModel() { return new BookmarkDatabase(mApp); } @NonNull @Provides @Singleton - public DownloadsModel provideDownloadsMode() { + public DownloadsModel provideDownloadsModel() { return new DownloadsDatabase(mApp); } + @NonNull + @Provides + @Singleton + public HistoryModel providesHistoryModel() { + return new HistoryDatabase(mApp); + } + @NonNull @Provides @Singleton diff --git a/app/src/main/java/acr/browser/lightning/constant/HistoryPage.java b/app/src/main/java/acr/browser/lightning/constant/HistoryPage.java index 11143fc..0e102ca 100644 --- a/app/src/main/java/acr/browser/lightning/constant/HistoryPage.java +++ b/app/src/main/java/acr/browser/lightning/constant/HistoryPage.java @@ -64,6 +64,7 @@ public class HistoryPage { @NonNull private final String mTitle; @Inject Application mApp; + @Inject HistoryModel mHistoryModel; public HistoryPage() { BrowserApp.getAppComponent().inject(this); @@ -77,7 +78,7 @@ public class HistoryPage { public void onSubscribe(@NonNull final SingleSubscriber subscriber) { final StringBuilder historyBuilder = new StringBuilder(HEADING_1 + mTitle + HEADING_2); - HistoryModel.lastHundredVisitedHistoryItems() + mHistoryModel.lastHundredVisitedHistoryItems() .subscribe(new SingleOnSubscribe>() { @Override public void onItem(@Nullable List item) { diff --git a/app/src/main/java/acr/browser/lightning/database/history/HistoryDatabase.java b/app/src/main/java/acr/browser/lightning/database/history/HistoryDatabase.java index e4e04ec..b61fa16 100644 --- a/app/src/main/java/acr/browser/lightning/database/history/HistoryDatabase.java +++ b/app/src/main/java/acr/browser/lightning/database/history/HistoryDatabase.java @@ -13,6 +13,13 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.WorkerThread; +import com.anthonycr.bonsai.Completable; +import com.anthonycr.bonsai.CompletableAction; +import com.anthonycr.bonsai.CompletableSubscriber; +import com.anthonycr.bonsai.Single; +import com.anthonycr.bonsai.SingleAction; +import com.anthonycr.bonsai.SingleSubscriber; + import java.util.ArrayList; import java.util.List; @@ -22,9 +29,15 @@ import javax.inject.Singleton; import acr.browser.lightning.R; import acr.browser.lightning.database.HistoryItem; + +/** + * The disk backed download database. + * See {@link HistoryModel} for method + * documentation. + */ @Singleton @WorkerThread -public class HistoryDatabase extends SQLiteOpenHelper { +public class HistoryDatabase extends SQLiteOpenHelper implements HistoryModel { // All Static variables // Database Version @@ -45,9 +58,8 @@ public class HistoryDatabase extends SQLiteOpenHelper { @Nullable private SQLiteDatabase mDatabase; @Inject - HistoryDatabase(@NonNull Application application) { + public HistoryDatabase(@NonNull Application application) { super(application, DATABASE_NAME, null, DATABASE_VERSION); - mDatabase = HistoryDatabase.this.getWritableDatabase(); } // Creating Tables @@ -87,33 +99,101 @@ public class HistoryDatabase extends SQLiteOpenHelper { return mDatabase; } - @WorkerThread - synchronized void deleteHistory() { - lazyDatabase().delete(TABLE_HISTORY, null, null); - lazyDatabase().close(); + @NonNull + @Override + public Completable deleteHistory() { + return Completable.create(new CompletableAction() { + @Override + public void onSubscribe(@NonNull CompletableSubscriber subscriber) { + lazyDatabase().delete(TABLE_HISTORY, null, null); + lazyDatabase().close(); + + subscriber.onComplete(); + } + }); } - @WorkerThread - synchronized void deleteHistoryItem(@NonNull String url) { - lazyDatabase().delete(TABLE_HISTORY, KEY_URL + " = ?", new String[]{url}); + @NonNull + @Override + public Completable deleteHistoryItem(@NonNull final String url) { + return Completable.create(new CompletableAction() { + @Override + public void onSubscribe(@NonNull CompletableSubscriber subscriber) { + lazyDatabase().delete(TABLE_HISTORY, KEY_URL + " = ?", new String[]{url}); + + subscriber.onComplete(); + } + }); } - @WorkerThread - synchronized void visitHistoryItem(@NonNull String url, @Nullable String title) { - ContentValues values = new ContentValues(); - values.put(KEY_TITLE, title == null ? "" : title); - values.put(KEY_TIME_VISITED, System.currentTimeMillis()); + @NonNull + @Override + public Completable visitHistoryItem(@NonNull final String url, @Nullable final String title) { + return Completable.create(new CompletableAction() { + @Override + public void onSubscribe(@NonNull CompletableSubscriber subscriber) { + ContentValues values = new ContentValues(); + values.put(KEY_TITLE, title == null ? "" : title); + values.put(KEY_TIME_VISITED, System.currentTimeMillis()); + + Cursor cursor = lazyDatabase().query(false, TABLE_HISTORY, new String[]{KEY_URL}, + KEY_URL + " = ?", new String[]{url}, null, null, null, "1"); + + if (cursor.getCount() > 0) { + lazyDatabase().update(TABLE_HISTORY, values, KEY_URL + " = ?", new String[]{url}); + } else { + addHistoryItem(new HistoryItem(url, title == null ? "" : title)); + } + + cursor.close(); + } + }); + } - Cursor cursor = lazyDatabase().query(false, TABLE_HISTORY, new String[]{KEY_URL}, - KEY_URL + " = ?", new String[]{url}, null, null, null, "1"); + @NonNull + @Override + public Single> findHistoryItemsContaining(@NonNull final String query) { + return Single.create(new SingleAction>() { + @Override + public void onSubscribe(@NonNull SingleSubscriber> subscriber) { + List itemList = new ArrayList<>(5); - if (cursor.getCount() > 0) { - lazyDatabase().update(TABLE_HISTORY, values, KEY_URL + " = ?", new String[]{url}); - } else { - addHistoryItem(new HistoryItem(url, title == null ? "" : title)); - } + String search = '%' + query + '%'; - cursor.close(); + Cursor cursor = lazyDatabase().query(TABLE_HISTORY, null, KEY_TITLE + " LIKE ? OR " + KEY_URL + " LIKE ?", + new String[]{search, search}, null, null, KEY_TIME_VISITED + " DESC", "5"); + + while (cursor.moveToNext()) { + itemList.add(fromCursor(cursor)); + } + + cursor.close(); + + subscriber.onItem(itemList); + subscriber.onComplete(); + } + }); + } + + @NonNull + @Override + public Single> lastHundredVisitedHistoryItems() { + return Single.create(new SingleAction>() { + @Override + public void onSubscribe(@NonNull SingleSubscriber> subscriber) { + List itemList = new ArrayList<>(100); + Cursor cursor = lazyDatabase().query(TABLE_HISTORY, null, null, null, null, null, KEY_TIME_VISITED + " DESC", "100"); + + while (cursor.moveToNext()) { + itemList.add(fromCursor(cursor)); + } + + cursor.close(); + + subscriber.onItem(itemList); + subscriber.onComplete(); + } + }); } @WorkerThread @@ -140,43 +220,6 @@ public class HistoryDatabase extends SQLiteOpenHelper { return m; } - @WorkerThread - @NonNull - synchronized List findItemsContaining(@Nullable String search) { - List itemList = new ArrayList<>(5); - if (search == null) { - return itemList; - } - - search = '%' + search + '%'; - - Cursor cursor = lazyDatabase().query(TABLE_HISTORY, null, KEY_TITLE + " LIKE ? OR " + KEY_URL + " LIKE ?", - new String[]{search, search}, null, null, KEY_TIME_VISITED + " DESC", "5"); - - while (cursor.moveToNext()) { - itemList.add(fromCursor(cursor)); - } - - cursor.close(); - - return itemList; - } - - @WorkerThread - @NonNull - synchronized List getLastHundredItems() { - List itemList = new ArrayList<>(100); - Cursor cursor = lazyDatabase().query(TABLE_HISTORY, null, null, null, null, null, KEY_TIME_VISITED + " DESC", "100"); - - while (cursor.moveToNext()) { - itemList.add(fromCursor(cursor)); - } - - cursor.close(); - - return itemList; - } - @WorkerThread @NonNull synchronized List getAllHistoryItems() { diff --git a/app/src/main/java/acr/browser/lightning/database/history/HistoryModel.java b/app/src/main/java/acr/browser/lightning/database/history/HistoryModel.java index 185ebcf..2aeb631 100644 --- a/app/src/main/java/acr/browser/lightning/database/history/HistoryModel.java +++ b/app/src/main/java/acr/browser/lightning/database/history/HistoryModel.java @@ -4,24 +4,19 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.anthonycr.bonsai.Completable; -import com.anthonycr.bonsai.CompletableAction; -import com.anthonycr.bonsai.CompletableSubscriber; import com.anthonycr.bonsai.Single; -import com.anthonycr.bonsai.SingleAction; -import com.anthonycr.bonsai.SingleSubscriber; import java.util.List; -import acr.browser.lightning.app.BrowserApp; import acr.browser.lightning.database.HistoryItem; /** - * A model class providing reactive bindings - * with the underlying history database. + * An interface that should be used to communicate + * with the history database. + *

+ * Created by anthonycr on 6/9/17. */ -public final class HistoryModel { - - private HistoryModel() {} +public interface HistoryModel { /** * An observable that deletes browser history. @@ -29,18 +24,7 @@ public final class HistoryModel { * @return a valid observable. */ @NonNull - public static Completable deleteHistory() { - return Completable.create(new CompletableAction() { - @Override - public void onSubscribe(@NonNull CompletableSubscriber subscriber) { - BrowserApp.getAppComponent() - .historyDatabase() - .deleteHistory(); - - subscriber.onComplete(); - } - }); - } + Completable deleteHistory(); /** * An observable that deletes the history @@ -50,18 +34,7 @@ public final class HistoryModel { * @return a valid observable. */ @NonNull - public static Completable deleteHistoryItem(@NonNull final String url) { - return Completable.create(new CompletableAction() { - @Override - public void onSubscribe(@NonNull CompletableSubscriber subscriber) { - BrowserApp.getAppComponent() - .historyDatabase() - .deleteHistoryItem(url); - - subscriber.onComplete(); - } - }); - } + Completable deleteHistoryItem(@NonNull final String url); /** * An observable that visits the URL by @@ -74,18 +47,7 @@ public final class HistoryModel { * @return a valid observable. */ @NonNull - public static Completable visitHistoryItem(@NonNull final String url, @Nullable final String title) { - return Completable.create(new CompletableAction() { - @Override - public void onSubscribe(@NonNull CompletableSubscriber subscriber) { - BrowserApp.getAppComponent() - .historyDatabase() - .visitHistoryItem(url, title); - - subscriber.onComplete(); - } - }); - } + Completable visitHistoryItem(@NonNull final String url, @Nullable final String title); /** * An observable that finds all history items @@ -100,18 +62,7 @@ public final class HistoryModel { * a list of history items. */ @NonNull - public static Single> findHistoryItemsContaining(@NonNull final String query) { - return Single.create(new SingleAction>() { - @Override - public void onSubscribe(@NonNull SingleSubscriber> subscriber) { - List result = BrowserApp.getAppComponent() - .historyDatabase().findItemsContaining(query); - - subscriber.onItem(result); - subscriber.onComplete(); - } - }); - } + Single> findHistoryItemsContaining(@NonNull final String query); /** * An observable that emits a list of the @@ -121,16 +72,5 @@ public final class HistoryModel { * a list of history items. */ @NonNull - public static Single> lastHundredVisitedHistoryItems() { - return Single.create(new SingleAction>() { - @Override - public void onSubscribe(@NonNull SingleSubscriber> subscriber) { - List result = BrowserApp.getAppComponent() - .historyDatabase().getLastHundredItems(); - - subscriber.onItem(result); - subscriber.onComplete(); - } - }); - } + Single> lastHundredVisitedHistoryItems(); } diff --git a/app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java b/app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java index 73fd6c2..26d9ed2 100644 --- a/app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java +++ b/app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java @@ -55,6 +55,7 @@ public class LightningDialogBuilder { @Inject BookmarkModel mBookmarkManager; @Inject DownloadsModel mDownloadsModel; + @Inject HistoryModel mHistoryModel; @Inject PreferenceManager mPreferenceManager; @Inject @@ -332,7 +333,7 @@ public class LightningDialogBuilder { new BrowserDialog.Item(R.string.dialog_remove_from_history) { @Override public void onClick() { - HistoryModel.deleteHistoryItem(url) + mHistoryModel.deleteHistoryItem(url) .subscribeOn(Schedulers.io()) .observeOn(Schedulers.main()) .subscribe(new CompletableOnSubscribe() { diff --git a/app/src/main/java/acr/browser/lightning/fragment/PrivacySettingsFragment.java b/app/src/main/java/acr/browser/lightning/fragment/PrivacySettingsFragment.java index f3d6ecc..d386d07 100644 --- a/app/src/main/java/acr/browser/lightning/fragment/PrivacySettingsFragment.java +++ b/app/src/main/java/acr/browser/lightning/fragment/PrivacySettingsFragment.java @@ -20,8 +20,11 @@ import com.anthonycr.bonsai.CompletableOnSubscribe; import com.anthonycr.bonsai.CompletableSubscriber; import com.anthonycr.bonsai.Schedulers; +import javax.inject.Inject; + import acr.browser.lightning.R; import acr.browser.lightning.app.BrowserApp; +import acr.browser.lightning.database.history.HistoryModel; import acr.browser.lightning.dialog.BrowserDialog; import acr.browser.lightning.utils.Utils; import acr.browser.lightning.utils.WebUtils; @@ -45,6 +48,8 @@ public class PrivacySettingsFragment extends LightningPreferenceFragment impleme private Activity mActivity; + @Inject HistoryModel mHistoryModel; + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -187,7 +192,8 @@ public class PrivacySettingsFragment extends LightningPreferenceFragment impleme public void onSubscribe(@NonNull CompletableSubscriber subscriber) { Activity activity = getActivity(); if (activity != null) { - WebUtils.clearHistory(activity); + // TODO: 6/9/17 clearHistory is not synchronous + WebUtils.clearHistory(activity, mHistoryModel); subscriber.onComplete(); } subscriber.onError(new RuntimeException("Activity was null in clearHistory")); diff --git a/app/src/main/java/acr/browser/lightning/search/SuggestionsAdapter.java b/app/src/main/java/acr/browser/lightning/search/SuggestionsAdapter.java index 2b3dd52..ccb4281 100644 --- a/app/src/main/java/acr/browser/lightning/search/SuggestionsAdapter.java +++ b/app/src/main/java/acr/browser/lightning/search/SuggestionsAdapter.java @@ -67,6 +67,7 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable { @Inject BookmarkModel mBookmarkManager; @Inject PreferenceManager mPreferenceManager; + @Inject HistoryModel mHistoryModel; @Inject Application mApplication; private final List mAllBookmarks = new ArrayList<>(5); @@ -197,7 +198,7 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable { @NonNull @Override public Filter getFilter() { - return new SearchFilter(this); + return new SearchFilter(this, mHistoryModel); } private synchronized void publishResults(@NonNull List list) { @@ -318,9 +319,12 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable { private static class SearchFilter extends Filter { @NonNull private final SuggestionsAdapter mSuggestionsAdapter; + @NonNull private final HistoryModel mHistoryModel; - SearchFilter(@NonNull SuggestionsAdapter suggestionsAdapter) { + SearchFilter(@NonNull SuggestionsAdapter suggestionsAdapter, + @NonNull HistoryModel historyModel) { mSuggestionsAdapter = suggestionsAdapter; + mHistoryModel = historyModel; } @NonNull @@ -355,7 +359,7 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable { } }); - HistoryModel.findHistoryItemsContaining(query) + mHistoryModel.findHistoryItemsContaining(query) .subscribeOn(Schedulers.io()) .observeOn(Schedulers.main()) .subscribe(new SingleOnSubscribe>() { diff --git a/app/src/main/java/acr/browser/lightning/utils/WebUtils.java b/app/src/main/java/acr/browser/lightning/utils/WebUtils.java index 2ae62c6..7b7825c 100644 --- a/app/src/main/java/acr/browser/lightning/utils/WebUtils.java +++ b/app/src/main/java/acr/browser/lightning/utils/WebUtils.java @@ -36,8 +36,8 @@ public class WebUtils { WebStorage.getInstance().deleteAllData(); } - public static void clearHistory(@NonNull Context context) { - HistoryModel.deleteHistory() + public static void clearHistory(@NonNull Context context, @NonNull HistoryModel historyModel) { + historyModel.deleteHistory() .subscribeOn(Schedulers.io()) .subscribe(); WebViewDatabase m = WebViewDatabase.getInstance(context); From 8a58fe9f8c66360a83d00ad9e2b08498b3e0e091 Mon Sep 17 00:00:00 2001 From: anthony restaino Date: Fri, 9 Jun 2017 20:39:51 -0400 Subject: [PATCH 10/56] Cleaning up History and Download Items --- .../browser/lightning/database/HistoryItem.java | 15 ++++++--------- .../database/downloads/DownloadItem.java | 12 ++++-------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/acr/browser/lightning/database/HistoryItem.java b/app/src/main/java/acr/browser/lightning/database/HistoryItem.java index 9021e73..9c0a041 100644 --- a/app/src/main/java/acr/browser/lightning/database/HistoryItem.java +++ b/app/src/main/java/acr/browser/lightning/database/HistoryItem.java @@ -11,21 +11,18 @@ import acr.browser.lightning.utils.Preconditions; public class HistoryItem implements Comparable { - // private variables - @NonNull - private String mUrl = ""; + @NonNull private String mUrl = ""; - @NonNull - private String mTitle = ""; + @NonNull private String mTitle = ""; - @NonNull - private String mFolder = ""; + @NonNull private String mFolder = ""; - @Nullable - private Bitmap mBitmap = null; + @Nullable private Bitmap mBitmap = null; private int mImageId = 0; + private int mPosition = 0; + private boolean mIsFolder = false; public HistoryItem() {} diff --git a/app/src/main/java/acr/browser/lightning/database/downloads/DownloadItem.java b/app/src/main/java/acr/browser/lightning/database/downloads/DownloadItem.java index 90025ba..eb06c6e 100644 --- a/app/src/main/java/acr/browser/lightning/database/downloads/DownloadItem.java +++ b/app/src/main/java/acr/browser/lightning/database/downloads/DownloadItem.java @@ -10,15 +10,11 @@ import acr.browser.lightning.utils.Preconditions; public class DownloadItem implements Comparable { - // private variables - @NonNull - private String mUrl = ""; + @NonNull private String mUrl = ""; - @NonNull - private String mTitle = ""; + @NonNull private String mTitle = ""; - @NonNull - private String mContentSize = ""; + @NonNull private String mContentSize = ""; public DownloadItem() {} @@ -83,7 +79,7 @@ public class DownloadItem implements Comparable { DownloadItem that = (DownloadItem) object; return this.mTitle.equals(that.mTitle) && this.mUrl.equals(that.mUrl) - && this.mContentSize.equals(that.mContentSize); + && this.mContentSize.equals(that.mContentSize); } @Override From 5f871787a51aa8bf136b88d7bfd7b32f5247ab15 Mon Sep 17 00:00:00 2001 From: anthony restaino Date: Fri, 9 Jun 2017 20:47:53 -0400 Subject: [PATCH 11/56] Fixing equals and dashcode for download and history items --- .../lightning/database/HistoryItem.java | 25 +++++++++++-------- .../database/downloads/DownloadItem.java | 17 +++++++------ 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/acr/browser/lightning/database/HistoryItem.java b/app/src/main/java/acr/browser/lightning/database/HistoryItem.java index 9c0a041..b921b2a 100644 --- a/app/src/main/java/acr/browser/lightning/database/HistoryItem.java +++ b/app/src/main/java/acr/browser/lightning/database/HistoryItem.java @@ -120,27 +120,30 @@ public class HistoryItem implements Comparable { } @Override - public boolean equals(@Nullable Object object) { + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; - if (this == object) return true; - if (object == null) return false; - if (!(object instanceof HistoryItem)) return false; + HistoryItem that = (HistoryItem) o; - HistoryItem that = (HistoryItem) object; + if (mImageId != that.mImageId) return false; + if (mPosition != that.mPosition) return false; + if (mIsFolder != that.mIsFolder) return false; + if (!mUrl.equals(that.mUrl)) return false; + if (!mTitle.equals(that.mTitle)) return false; + + return mFolder.equals(that.mFolder); - return mImageId == that.mImageId && - this.mTitle.equals(that.mTitle) && this.mUrl.equals(that.mUrl) && - this.mFolder.equals(that.mFolder); } @Override public int hashCode() { - int result = mUrl.hashCode(); - result = 31 * result + mImageId; result = 31 * result + mTitle.hashCode(); - result = 32 * result + mFolder.hashCode(); + result = 31 * result + mFolder.hashCode(); result = 31 * result + mImageId; + result = 31 * result + mPosition; + result = 31 * result + (mIsFolder ? 1 : 0); return result; } diff --git a/app/src/main/java/acr/browser/lightning/database/downloads/DownloadItem.java b/app/src/main/java/acr/browser/lightning/database/downloads/DownloadItem.java index eb06c6e..f87e4a1 100644 --- a/app/src/main/java/acr/browser/lightning/database/downloads/DownloadItem.java +++ b/app/src/main/java/acr/browser/lightning/database/downloads/DownloadItem.java @@ -70,23 +70,24 @@ public class DownloadItem implements Comparable { } @Override - public boolean equals(@Nullable Object object) { + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; - if (this == object) return true; - if (object == null) return false; - if (!(object instanceof DownloadItem)) return false; + DownloadItem that = (DownloadItem) o; - DownloadItem that = (DownloadItem) object; + if (!mUrl.equals(that.mUrl)) return false; + if (!mTitle.equals(that.mTitle)) return false; + + return mContentSize.equals(that.mContentSize); - return this.mTitle.equals(that.mTitle) && this.mUrl.equals(that.mUrl) - && this.mContentSize.equals(that.mContentSize); } @Override public int hashCode() { - int result = mUrl.hashCode(); result = 31 * result + mTitle.hashCode(); + result = 31 * result + mContentSize.hashCode(); return result; } From ee2cf5fd3512f19f986948037f50ee1f255d5c80 Mon Sep 17 00:00:00 2001 From: anthony restaino Date: Sat, 10 Jun 2017 09:45:35 -0400 Subject: [PATCH 12/56] Adding favicons read off disk to memory cache --- .../java/acr/browser/lightning/favicon/FaviconModel.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/acr/browser/lightning/favicon/FaviconModel.java b/app/src/main/java/acr/browser/lightning/favicon/FaviconModel.java index e9ecf6c..02c7ee5 100644 --- a/app/src/main/java/acr/browser/lightning/favicon/FaviconModel.java +++ b/app/src/main/java/acr/browser/lightning/favicon/FaviconModel.java @@ -136,11 +136,14 @@ public class FaviconModel { File faviconCacheFile = createFaviconCacheFile(mApplication, uri); - Bitmap favicon = getFaviconFromMemCache(url); if (faviconCacheFile.exists() && favicon == null) { favicon = mImageFetcher.retrieveFaviconFromCache(faviconCacheFile); + + if (favicon != null) { + addFaviconToMemCache(url, favicon); + } } if (favicon == null) { From 334dbb37805f4ac99be861a16805fce32eb6c0ae Mon Sep 17 00:00:00 2001 From: DF1E Date: Sat, 10 Jun 2017 20:14:18 +0200 Subject: [PATCH 13/56] downloads - show message if file doesn't exist --- .../acr/browser/lightning/view/LightningWebClient.java | 7 ++++--- app/src/main/res/values-de/strings.xml | 3 ++- app/src/main/res/values/strings.xml | 1 + 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/acr/browser/lightning/view/LightningWebClient.java b/app/src/main/java/acr/browser/lightning/view/LightningWebClient.java index f6861fd..c40b302 100644 --- a/app/src/main/java/acr/browser/lightning/view/LightningWebClient.java +++ b/app/src/main/java/acr/browser/lightning/view/LightningWebClient.java @@ -366,8 +366,7 @@ public class LightningWebClient extends WebViewClient { String newMimeType = MimeTypeMap.getSingleton() .getMimeTypeFromExtension(Utils.guessFileExtension(file.toString())); - Intent intent = new Intent(); - intent.setAction(Intent.ACTION_VIEW); + Intent intent = new Intent(Intent.ACTION_VIEW); intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); Uri contentUri = FileProvider.getUriForFile(mActivity, BuildConfig.APPLICATION_ID + ".fileprovider", file); intent.setDataAndType(contentUri, newMimeType); @@ -377,8 +376,10 @@ public class LightningWebClient extends WebViewClient { } catch (Exception e) { System.out.println("LightningWebClient: cannot open downloaded file"); } - return true; + } else { + Utils.showSnackbar(mActivity, R.string.message_open_download_fail); } + return true; } return false; } diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index a6b6bf3..7cc7b91 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -160,7 +160,7 @@ Exportiere Datensicherung Importiere Lesezeichen aus Datensicherung Lesezeichen exportiert nach - Lesezeichen Einstellungen + Lesezeichen Lesezeichen konnten nicht importiert werden Wähle Datei aus Allgemein @@ -246,4 +246,5 @@ Host: Quelle für Werbeblocker Anzeige + Diese Datei existiert nicht mehr diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bfee5cf..c890aa0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -229,6 +229,7 @@ Delete all bookmarks Flash Player is not supported by your system Upgrade to Lightning Plus to block ads + This file doesn\'t exist anymore FAQ Frequently asked questions From e850d26abb5b90a97a75106e82d60e4c66d7860e Mon Sep 17 00:00:00 2001 From: DF1E Date: Sat, 10 Jun 2017 20:26:27 +0200 Subject: [PATCH 14/56] inject DownloadHandler + don't save downloads in incognito --- .../browser/lightning/app/AppComponent.java | 3 + .../acr/browser/lightning/app/AppModule.java | 8 + .../dialog/LightningDialogBuilder.java | 17 +- .../lightning/download/DownloadHandler.java | 157 ++++++------------ .../download/LightningDownloadListener.java | 17 +- .../fragment/GeneralSettingsFragment.java | 10 +- .../preference/PreferenceManager.java | 4 +- .../browser/lightning/utils/FileUtils.java | 86 ++++++++++ .../acr/browser/lightning/utils/Utils.java | 36 ---- 9 files changed, 158 insertions(+), 180 deletions(-) diff --git a/app/src/main/java/acr/browser/lightning/app/AppComponent.java b/app/src/main/java/acr/browser/lightning/app/AppComponent.java index 8ca9d5c..c47e3f4 100644 --- a/app/src/main/java/acr/browser/lightning/app/AppComponent.java +++ b/app/src/main/java/acr/browser/lightning/app/AppComponent.java @@ -14,6 +14,7 @@ import acr.browser.lightning.constant.HistoryPage; import acr.browser.lightning.constant.StartPage; import acr.browser.lightning.database.history.HistoryDatabase; import acr.browser.lightning.dialog.LightningDialogBuilder; +import acr.browser.lightning.download.DownloadHandler; import acr.browser.lightning.download.LightningDownloadListener; import acr.browser.lightning.fragment.BookmarkSettingsFragment; import acr.browser.lightning.fragment.BookmarksFragment; @@ -80,6 +81,8 @@ public interface AppComponent { void inject(LightningChromeClient chromeClient); + void inject(DownloadHandler downloadHandler); + HistoryDatabase historyDatabase(); } diff --git a/app/src/main/java/acr/browser/lightning/app/AppModule.java b/app/src/main/java/acr/browser/lightning/app/AppModule.java index 9ae607a..32fbf0c 100644 --- a/app/src/main/java/acr/browser/lightning/app/AppModule.java +++ b/app/src/main/java/acr/browser/lightning/app/AppModule.java @@ -14,6 +14,7 @@ import acr.browser.lightning.database.downloads.DownloadsDatabase; import acr.browser.lightning.database.downloads.DownloadsModel; import acr.browser.lightning.database.history.HistoryDatabase; import acr.browser.lightning.database.history.HistoryModel; +import acr.browser.lightning.download.DownloadHandler; import dagger.Module; import dagger.Provides; @@ -56,6 +57,13 @@ public class AppModule { return new HistoryDatabase(mApp); } + @NonNull + @Provides + @Singleton + public DownloadHandler provideDownloadHandler() { + return new DownloadHandler(); + } + @NonNull @Provides @Singleton diff --git a/app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java b/app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java index 26d9ed2..7d7d8eb 100644 --- a/app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java +++ b/app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java @@ -8,9 +8,7 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v7.app.AlertDialog; import android.text.TextUtils; -import android.util.Log; import android.view.View; -import android.webkit.URLUtil; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; import android.widget.EditText; @@ -31,13 +29,12 @@ import acr.browser.lightning.constant.Constants; import acr.browser.lightning.controller.UIController; import acr.browser.lightning.database.HistoryItem; import acr.browser.lightning.database.bookmark.BookmarkModel; -import acr.browser.lightning.database.downloads.DownloadItem; import acr.browser.lightning.database.downloads.DownloadsModel; import acr.browser.lightning.database.history.HistoryModel; +import acr.browser.lightning.download.DownloadHandler; import acr.browser.lightning.preference.PreferenceManager; import acr.browser.lightning.utils.IntentUtils; import acr.browser.lightning.utils.Preconditions; -import acr.browser.lightning.utils.Utils; /** * TODO Rename this class it doesn't build dialogs only for bookmarks @@ -57,6 +54,7 @@ public class LightningDialogBuilder { @Inject DownloadsModel mDownloadsModel; @Inject HistoryModel mHistoryModel; @Inject PreferenceManager mPreferenceManager; + @Inject DownloadHandler mDownloadHandler; @Inject public LightningDialogBuilder() { @@ -385,16 +383,7 @@ public class LightningDialogBuilder { new BrowserDialog.Item(R.string.dialog_download_image) { @Override public void onClick() { - Utils.downloadFile(activity, mPreferenceManager, url, userAgent, "attachment"); - - mDownloadsModel.addDownloadIfNotExists(new DownloadItem(url, URLUtil.guessFileName(url, null, null), "")) - .subscribe(new SingleOnSubscribe() { - @Override - public void onItem(@Nullable Boolean item) { - if (item != null && !item) - Log.i(TAG, "error saving download to database"); - } - }); + mDownloadHandler.onDownloadStart(activity, mPreferenceManager, url, userAgent, "attachment", null, ""); } }); } diff --git a/app/src/main/java/acr/browser/lightning/download/DownloadHandler.java b/app/src/main/java/acr/browser/lightning/download/DownloadHandler.java index 6f02b92..2bc9344 100644 --- a/app/src/main/java/acr/browser/lightning/download/DownloadHandler.java +++ b/app/src/main/java/acr/browser/lightning/download/DownloadHandler.java @@ -23,16 +23,26 @@ import android.webkit.CookieManager; import android.webkit.MimeTypeMap; import android.webkit.URLUtil; +import com.anthonycr.bonsai.SingleOnSubscribe; + import java.io.File; import java.io.IOException; +import javax.inject.Inject; + import acr.browser.lightning.BuildConfig; import acr.browser.lightning.R; +import acr.browser.lightning.activity.BrowserActivity; import acr.browser.lightning.activity.MainActivity; +import acr.browser.lightning.app.BrowserApp; import acr.browser.lightning.constant.Constants; +import acr.browser.lightning.database.downloads.DownloadItem; +import acr.browser.lightning.database.downloads.DownloadsModel; import acr.browser.lightning.dialog.BrowserDialog; import acr.browser.lightning.preference.PreferenceManager; +import acr.browser.lightning.utils.FileUtils; import acr.browser.lightning.utils.Utils; +import acr.browser.lightning.view.LightningView; /** * Handle download requests @@ -43,9 +53,11 @@ public class DownloadHandler { private static final String COOKIE_REQUEST_HEADER = "Cookie"; - public static final String DEFAULT_DOWNLOAD_PATH = - Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) - .getPath(); + @Inject DownloadsModel downloadsModel; + + public DownloadHandler() { + BrowserApp.getAppComponent().inject(this); + } /** * Notify the host application a download should be done, or that the data @@ -56,9 +68,10 @@ public class DownloadHandler { * @param userAgent User agent of the downloading application. * @param contentDisposition Content-disposition http header, if present. * @param mimetype The mimetype of the content reported by the server + * @param contentSize The size of the content */ - public static void onDownloadStart(@NonNull Activity context, @NonNull PreferenceManager manager, String url, String userAgent, - @Nullable String contentDisposition, String mimetype) { + public void onDownloadStart(@NonNull Activity context, @NonNull PreferenceManager manager, String url, String userAgent, + @Nullable String contentDisposition, String mimetype, String contentSize) { Log.d(TAG, "DOWNLOAD: Trying to download from URL: " + url); Log.d(TAG, "DOWNLOAD: Content disposition: " + contentDisposition); @@ -68,7 +81,7 @@ public class DownloadHandler { // if we're dealing wih A/V content that's not explicitly marked // for download, check if it's streamable. if (contentDisposition == null - || !contentDisposition.regionMatches(true, 0, "attachment", 0, 10)) { + || !contentDisposition.regionMatches(true, 0, "attachment", 0, 10)) { // query the package manager to see if there's a registered handler // that matches. Intent intent = new Intent(Intent.ACTION_VIEW); @@ -80,12 +93,12 @@ public class DownloadHandler { intent.setSelector(null); } ResolveInfo info = context.getPackageManager().resolveActivity(intent, - PackageManager.MATCH_DEFAULT_ONLY); + PackageManager.MATCH_DEFAULT_ONLY); if (info != null) { // If we resolved to ourselves, we don't want to attempt to // load the url only to try and download it again. if (BuildConfig.APPLICATION_ID.equals(info.activityInfo.packageName) - || MainActivity.class.getName().equals(info.activityInfo.name)) { + || MainActivity.class.getName().equals(info.activityInfo.name)) { // someone (other than us) knows how to handle this mime // type with this scheme, don't download. try { @@ -98,7 +111,7 @@ public class DownloadHandler { } } } - onDownloadStartNoStream(context, manager, url, userAgent, contentDisposition, mimetype); + onDownloadStartNoStream(context, manager, url, userAgent, contentDisposition, mimetype, contentSize); } // This is to work around the fact that java.net.URI throws Exceptions @@ -141,11 +154,12 @@ public class DownloadHandler { * @param userAgent User agent of the downloading application. * @param contentDisposition Content-disposition http header, if present. * @param mimetype The mimetype of the content reported by the server + * @param contentSize The size of the content */ /* package */ - private static void onDownloadStartNoStream(@NonNull final Activity context, @NonNull PreferenceManager preferences, - String url, String userAgent, - String contentDisposition, @Nullable String mimetype) { + private void onDownloadStartNoStream(@NonNull final Activity context, @NonNull PreferenceManager preferences, + String url, String userAgent, + String contentDisposition, @Nullable String mimetype, String contentSize) { final String filename = URLUtil.guessFileName(url, contentDisposition, mimetype); // Check to see if we have an SDCard @@ -164,8 +178,8 @@ public class DownloadHandler { } Dialog dialog = new AlertDialog.Builder(context).setTitle(title) - .setIcon(android.R.drawable.ic_dialog_alert).setMessage(msg) - .setPositiveButton(R.string.action_ok, null).show(); + .setIcon(android.R.drawable.ic_dialog_alert).setMessage(msg) + .setPositiveButton(R.string.action_ok, null).show(); BrowserDialog.setDialogSize(context, dialog); return; } @@ -198,16 +212,8 @@ public class DownloadHandler { // or, should it be set to one of several Environment.DIRECTORY* dirs // depending on mimetype? String location = preferences.getDownloadDirectory(); - Uri downloadFolder; - location = addNecessarySlashes(location); - downloadFolder = Uri.parse(location); - - File dir = new File(downloadFolder.getPath()); - if (!dir.isDirectory() && !dir.mkdirs()) { - // Cannot make the directory - Utils.showSnackbar(context, R.string.problem_location_download); - return; - } + location = FileUtils.addNecessarySlashes(location); + Uri downloadFolder = Uri.parse(location); if (!isWriteAccessAvailable(downloadFolder)) { Utils.showSnackbar(context, R.string.problem_location_download); @@ -240,7 +246,7 @@ public class DownloadHandler { } else { Log.d(TAG, "Valid mimetype, attempting to download"); final DownloadManager manager = (DownloadManager) context - .getSystemService(Context.DOWNLOAD_SERVICE); + .getSystemService(Context.DOWNLOAD_SERVICE); try { manager.enqueue(request); } catch (IllegalArgumentException e) { @@ -254,80 +260,30 @@ public class DownloadHandler { } Utils.showSnackbar(context, context.getString(R.string.download_pending) + ' ' + filename); } - } - - private static final String sFileName = "test"; - private static final String sFileExtension = ".txt"; - /** - * Determine whether there is write access in the given directory. Returns false if a - * file cannot be created in the directory or if the directory does not exist. - * - * @param directory the directory to check for write access - * @return returns true if the directory can be written to or is in a directory that can - * be written to. false if there is no write access. - */ - public static boolean isWriteAccessAvailable(@Nullable String directory) { - if (directory == null || directory.isEmpty()) { - return false; - } - String dir = addNecessarySlashes(directory); - dir = getFirstRealParentDirectory(dir); - File file = new File(dir + sFileName + sFileExtension); - for (int n = 0; n < 100; n++) { - if (!file.exists()) { - try { - if (file.createNewFile()) { - //noinspection ResultOfMethodCallIgnored - file.delete(); - } - return true; - } catch (IOException ignored) { - return false; - } - } else { - file = new File(dir + sFileName + '-' + n + sFileExtension); - } - } - return file.canWrite(); - } + // save download in database + BrowserActivity browserActivity = (BrowserActivity) context; + LightningView view = browserActivity.getTabModel().getCurrentTab(); - /** - * Returns the first parent directory of a directory that exists. This is useful - * for subdirectories that do not exist but their parents do. - * - * @param directory the directory to find the first existent parent - * @return the first existent parent - */ - @Nullable - private static String getFirstRealParentDirectory(@Nullable String directory) { - while (true) { - if (directory == null || directory.isEmpty()) { - return "/"; - } - directory = addNecessarySlashes(directory); - File file = new File(directory); - if (!file.isDirectory()) { - int indexSlash = directory.lastIndexOf('/'); - if (indexSlash > 0) { - String parent = directory.substring(0, indexSlash); - int previousIndex = parent.lastIndexOf('/'); - if (previousIndex > 0) { - directory = parent.substring(0, previousIndex); - } else { - return "/"; - } - } else { - return "/"; - } - } else { - return directory; - } + if (view != null && !view.isIncognito()) { + downloadsModel.addDownloadIfNotExists(new DownloadItem(url, filename, contentSize)) + .subscribe(new SingleOnSubscribe() { + @Override + public void onItem(@Nullable Boolean item) { + if (item != null && !item) + Log.i(TAG, "error saving download to database"); + } + }); } } private static boolean isWriteAccessAvailable(@NonNull Uri fileUri) { File file = new File(fileUri.getPath()); + + if (!file.isDirectory() && !file.mkdirs()) { + return false; + } + try { if (file.createNewFile()) { //noinspection ResultOfMethodCallIgnored @@ -338,19 +294,4 @@ public class DownloadHandler { return false; } } - - @NonNull - public static String addNecessarySlashes(@Nullable String originalPath) { - if (originalPath == null || originalPath.length() == 0) { - return "/"; - } - if (originalPath.charAt(originalPath.length() - 1) != '/') { - originalPath = originalPath + '/'; - } - if (originalPath.charAt(0) != '/') { - originalPath = '/' + originalPath; - } - return originalPath; - } - -} +} \ No newline at end of file diff --git a/app/src/main/java/acr/browser/lightning/download/LightningDownloadListener.java b/app/src/main/java/acr/browser/lightning/download/LightningDownloadListener.java index a38bb93..febdb08 100644 --- a/app/src/main/java/acr/browser/lightning/download/LightningDownloadListener.java +++ b/app/src/main/java/acr/browser/lightning/download/LightningDownloadListener.java @@ -7,7 +7,6 @@ import android.Manifest; import android.app.Activity; import android.app.Dialog; import android.content.DialogInterface; -import android.support.annotation.Nullable; import android.support.v7.app.AlertDialog; import android.text.format.Formatter; import android.util.Log; @@ -16,12 +15,10 @@ import android.webkit.URLUtil; import acr.browser.lightning.R; import acr.browser.lightning.app.BrowserApp; -import acr.browser.lightning.database.downloads.DownloadItem; import acr.browser.lightning.database.downloads.DownloadsModel; import acr.browser.lightning.dialog.BrowserDialog; import acr.browser.lightning.preference.PreferenceManager; -import com.anthonycr.bonsai.SingleOnSubscribe; import com.anthonycr.grant.PermissionsManager; import com.anthonycr.grant.PermissionsResultAction; @@ -34,7 +31,7 @@ public class LightningDownloadListener implements DownloadListener { private final Activity mActivity; @Inject PreferenceManager mPreferenceManager; - + @Inject DownloadHandler mDownloadHandler; @Inject DownloadsModel downloadsModel; public LightningDownloadListener(Activity context) { @@ -64,17 +61,7 @@ public class LightningDownloadListener implements DownloadListener { public void onClick(DialogInterface dialog, int which) { switch (which) { case DialogInterface.BUTTON_POSITIVE: - DownloadHandler.onDownloadStart(mActivity, mPreferenceManager, url, userAgent, - contentDisposition, mimetype); - - downloadsModel.addDownloadIfNotExists(new DownloadItem(url, fileName, downloadSize)) - .subscribe(new SingleOnSubscribe() { - @Override - public void onItem(@Nullable Boolean item) { - if (item != null && !item) - Log.i(TAG, "error saving download to database"); - } - }); + mDownloadHandler.onDownloadStart(mActivity, mPreferenceManager, url, userAgent, "attachment", null, ""); break; case DialogInterface.BUTTON_NEGATIVE: break; diff --git a/app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java b/app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java index 3d11cd1..70db8dc 100644 --- a/app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java +++ b/app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java @@ -25,7 +25,7 @@ import acr.browser.lightning.BuildConfig; import acr.browser.lightning.R; import acr.browser.lightning.constant.Constants; import acr.browser.lightning.dialog.BrowserDialog; -import acr.browser.lightning.download.DownloadHandler; +import acr.browser.lightning.utils.FileUtils; import acr.browser.lightning.utils.ProxyUtils; import acr.browser.lightning.utils.ThemeUtils; import acr.browser.lightning.utils.Utils; @@ -459,8 +459,8 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme public void onClick(DialogInterface dialog, int which) { switch (which) { case 0: - mPreferenceManager.setDownloadDirectory(DownloadHandler.DEFAULT_DOWNLOAD_PATH); - downloadloc.setSummary(DownloadHandler.DEFAULT_DOWNLOAD_PATH); + mPreferenceManager.setDownloadDirectory(FileUtils.DEFAULT_DOWNLOAD_PATH); + downloadloc.setSummary(FileUtils.DEFAULT_DOWNLOAD_PATH); break; case 1: downPicker(); @@ -539,7 +539,7 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme @Override public void onClick(DialogInterface dialog, int which) { String text = getDownload.getText().toString(); - text = DownloadHandler.addNecessarySlashes(text); + text = FileUtils.addNecessarySlashes(text); mPreferenceManager.setDownloadDirectory(text); downloadloc.setSummary(text); } @@ -667,7 +667,7 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme @Override public void afterTextChanged(@NonNull Editable s) { - if (!DownloadHandler.isWriteAccessAvailable(s.toString())) { + if (!FileUtils.isWriteAccessAvailable(s.toString())) { this.getDownload.setTextColor(this.errorColor); } else { this.getDownload.setTextColor(this.regularColor); diff --git a/app/src/main/java/acr/browser/lightning/preference/PreferenceManager.java b/app/src/main/java/acr/browser/lightning/preference/PreferenceManager.java index 8be0ac5..d052eac 100644 --- a/app/src/main/java/acr/browser/lightning/preference/PreferenceManager.java +++ b/app/src/main/java/acr/browser/lightning/preference/PreferenceManager.java @@ -9,7 +9,7 @@ import javax.inject.Inject; import javax.inject.Singleton; import acr.browser.lightning.constant.Constants; -import acr.browser.lightning.download.DownloadHandler; +import acr.browser.lightning.utils.FileUtils; @Singleton public class PreferenceManager { @@ -150,7 +150,7 @@ public class PreferenceManager { @NonNull public String getDownloadDirectory() { - return mPrefs.getString(Name.DOWNLOAD_DIRECTORY, DownloadHandler.DEFAULT_DOWNLOAD_PATH); + return mPrefs.getString(Name.DOWNLOAD_DIRECTORY, FileUtils.DEFAULT_DOWNLOAD_PATH); } public int getFlashSupport() { diff --git a/app/src/main/java/acr/browser/lightning/utils/FileUtils.java b/app/src/main/java/acr/browser/lightning/utils/FileUtils.java index 0ac8135..d272c43 100644 --- a/app/src/main/java/acr/browser/lightning/utils/FileUtils.java +++ b/app/src/main/java/acr/browser/lightning/utils/FileUtils.java @@ -28,6 +28,9 @@ public class FileUtils { private static final String TAG = "FileUtils"; + public static final String DEFAULT_DOWNLOAD_PATH = + Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath(); + /** * Writes a bundle to persistent storage in the files directory * using the specified file name. This method is a blocking @@ -160,4 +163,87 @@ public class FileUtils { return megaBytes * 1024 * 1024; } + /** + * Determine whether there is write access in the given directory. Returns false if a + * file cannot be created in the directory or if the directory does not exist. + * + * @param directory the directory to check for write access + * @return returns true if the directory can be written to or is in a directory that can + * be written to. false if there is no write access. + */ + public static boolean isWriteAccessAvailable(@Nullable String directory) { + if (directory == null || directory.isEmpty()) { + return false; + } + + final String sFileName = "test"; + final String sFileExtension = ".txt"; + String dir = addNecessarySlashes(directory); + dir = getFirstRealParentDirectory(dir); + File file = new File(dir + sFileName + sFileExtension); + for (int n = 0; n < 100; n++) { + if (!file.exists()) { + try { + if (file.createNewFile()) { + //noinspection ResultOfMethodCallIgnored + file.delete(); + } + return true; + } catch (IOException ignored) { + return false; + } + } else { + file = new File(dir + sFileName + '-' + n + sFileExtension); + } + } + return file.canWrite(); + } + + /** + * Returns the first parent directory of a directory that exists. This is useful + * for subdirectories that do not exist but their parents do. + * + * @param directory the directory to find the first existent parent + * @return the first existent parent + */ + @Nullable + private static String getFirstRealParentDirectory(@Nullable String directory) { + while (true) { + if (directory == null || directory.isEmpty()) { + return "/"; + } + directory = addNecessarySlashes(directory); + File file = new File(directory); + if (!file.isDirectory()) { + int indexSlash = directory.lastIndexOf('/'); + if (indexSlash > 0) { + String parent = directory.substring(0, indexSlash); + int previousIndex = parent.lastIndexOf('/'); + if (previousIndex > 0) { + directory = parent.substring(0, previousIndex); + } else { + return "/"; + } + } else { + return "/"; + } + } else { + return directory; + } + } + } + + @NonNull + public static String addNecessarySlashes(@Nullable String originalPath) { + if (originalPath == null || originalPath.length() == 0) { + return "/"; + } + if (originalPath.charAt(originalPath.length() - 1) != '/') { + originalPath = originalPath + '/'; + } + if (originalPath.charAt(0) != '/') { + originalPath = '/' + originalPath; + } + return originalPath; + } } diff --git a/app/src/main/java/acr/browser/lightning/utils/Utils.java b/app/src/main/java/acr/browser/lightning/utils/Utils.java index b626582..8bcbe3d 100644 --- a/app/src/main/java/acr/browser/lightning/utils/Utils.java +++ b/app/src/main/java/acr/browser/lightning/utils/Utils.java @@ -3,7 +3,6 @@ */ package acr.browser.lightning.utils; -import android.Manifest; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; @@ -33,12 +32,8 @@ import android.text.TextUtils; import android.util.DisplayMetrics; import android.util.Log; import android.view.View; -import android.webkit.URLUtil; import android.widget.Toast; -import com.anthonycr.grant.PermissionsManager; -import com.anthonycr.grant.PermissionsResultAction; - import java.io.Closeable; import java.io.File; import java.io.IOException; @@ -52,8 +47,6 @@ import acr.browser.lightning.activity.MainActivity; import acr.browser.lightning.constant.Constants; import acr.browser.lightning.database.HistoryItem; import acr.browser.lightning.dialog.BrowserDialog; -import acr.browser.lightning.download.DownloadHandler; -import acr.browser.lightning.preference.PreferenceManager; public final class Utils { @@ -63,35 +56,6 @@ public final class Utils { return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; } - /** - * Downloads a file from the specified URL. Handles permissions - * requests, and creates all the necessary dialogs that must be - * showed to the user. - * - * @param activity activity needed to created dialogs. - * @param url url to download from. - * @param userAgent the user agent of the browser. - * @param contentDisposition the content description of the file. - */ - public static void downloadFile(@NonNull final Activity activity, @NonNull final PreferenceManager manager, final String url, - final String userAgent, final String contentDisposition) { - PermissionsManager.getInstance().requestPermissionsIfNecessaryForResult(activity, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, - Manifest.permission.WRITE_EXTERNAL_STORAGE}, new PermissionsResultAction() { - @Override - public void onGranted() { - String fileName = URLUtil.guessFileName(url, null, null); - DownloadHandler.onDownloadStart(activity, manager, url, userAgent, contentDisposition, null); - Log.i(TAG, "Downloading: " + fileName); - } - - @Override - public void onDenied(String permission) { - // TODO Show Message - } - }); - - } - /** * Creates a new intent that can launch the email * app with a subject, address, body, and cc. It From 3b8f85a86ad9796c9fc3d1aff769d30720b4e03c Mon Sep 17 00:00:00 2001 From: anthony restaino Date: Sat, 10 Jun 2017 16:30:46 -0400 Subject: [PATCH 15/56] Fixing history and download item sorting --- .../main/java/acr/browser/lightning/database/HistoryItem.java | 2 +- .../acr/browser/lightning/database/downloads/DownloadItem.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/acr/browser/lightning/database/HistoryItem.java b/app/src/main/java/acr/browser/lightning/database/HistoryItem.java index b921b2a..7913864 100644 --- a/app/src/main/java/acr/browser/lightning/database/HistoryItem.java +++ b/app/src/main/java/acr/browser/lightning/database/HistoryItem.java @@ -112,7 +112,7 @@ public class HistoryItem implements Comparable { @Override public int compareTo(@NonNull HistoryItem another) { - int compare = this.mTitle.compareTo(another.mTitle); + int compare = this.mTitle.compareToIgnoreCase(another.mTitle); if (compare == 0) { return this.mUrl.compareTo(another.mUrl); } diff --git a/app/src/main/java/acr/browser/lightning/database/downloads/DownloadItem.java b/app/src/main/java/acr/browser/lightning/database/downloads/DownloadItem.java index f87e4a1..b45abb6 100644 --- a/app/src/main/java/acr/browser/lightning/database/downloads/DownloadItem.java +++ b/app/src/main/java/acr/browser/lightning/database/downloads/DownloadItem.java @@ -62,7 +62,7 @@ public class DownloadItem implements Comparable { @Override public int compareTo(@NonNull DownloadItem another) { - int compare = this.mTitle.compareTo(another.mTitle); + int compare = this.mTitle.compareToIgnoreCase(another.mTitle); if (compare == 0) { return this.mUrl.compareTo(another.mUrl); } From 0e55c653b0d383609179b126b0e73244e444c8f0 Mon Sep 17 00:00:00 2001 From: anthony restaino Date: Sun, 11 Jun 2017 16:56:34 -0400 Subject: [PATCH 16/56] Nice color default icons for bookmarks --- .../lightning/favicon/FaviconModel.java | 36 +++++++--- .../lightning/fragment/BookmarksFragment.java | 2 +- .../lightning/utils/DrawableUtils.java | 69 +++++++++++++++++++ .../main/res/layout/bookmark_list_item.xml | 4 +- app/src/main/res/raw/default_bookmarks.dat | 8 +-- app/src/main/res/values/colors.xml | 5 ++ app/src/main/res/values/dimens.xml | 2 + 7 files changed, 109 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/acr/browser/lightning/favicon/FaviconModel.java b/app/src/main/java/acr/browser/lightning/favicon/FaviconModel.java index 02c7ee5..3dbfaad 100644 --- a/app/src/main/java/acr/browser/lightning/favicon/FaviconModel.java +++ b/app/src/main/java/acr/browser/lightning/favicon/FaviconModel.java @@ -3,6 +3,7 @@ package acr.browser.lightning.favicon; import android.app.Application; import android.graphics.Bitmap; import android.net.Uri; +import android.support.annotation.ColorInt; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.util.Log; @@ -22,6 +23,8 @@ import java.io.IOException; import javax.inject.Inject; import javax.inject.Singleton; +import acr.browser.lightning.R; +import acr.browser.lightning.utils.DrawableUtils; import acr.browser.lightning.utils.FileUtils; import acr.browser.lightning.utils.Preconditions; import acr.browser.lightning.utils.Utils; @@ -44,10 +47,13 @@ public class FaviconModel { } }; + private final int mBookmarkIconSize; + @Inject FaviconModel(@NonNull Application application) { mImageFetcher = new ImageFetcher(); mApplication = application; + mBookmarkIconSize = mApplication.getResources().getDimensionPixelSize(R.dimen.bookmark_item_icon_size); } /** @@ -68,6 +74,16 @@ public class FaviconModel { } } + @NonNull + private Bitmap getDefaultBitmapForCharacter(@NonNull Character character) { + @ColorInt int defaultFaviconColor = DrawableUtils.characterToColorHash(character, mApplication); + + return DrawableUtils.getRoundedLetterImage(character, + mBookmarkIconSize, + mBookmarkIconSize, + defaultFaviconColor); + } + /** * Adds a bitmap to the memory cache * for the given URL. @@ -106,18 +122,15 @@ public class FaviconModel { * Retrieves the favicon for a URL, * may be from network or cache. * - * @param url the URL that we should retrieve the + * @param url The URL that we should retrieve the * favicon for. - * @param defaultFavicon the default favicon if no - * favicon is found. - * @param allowGoogleService true to allow grabbing favicons - * from Google, false otherwise. - * @return an observable that emits a bitmap if one is found, - * or the default if none was found. + * @param title The title for the web page. + * @param allowGoogleService True to allow grabbing favicons + * from Google, false otherwise. @return an observable that emits a bitmap if one is found, */ @NonNull public Single faviconForUrl(@NonNull final String url, - @NonNull final Bitmap defaultFavicon, + @NonNull final String title, final boolean allowGoogleService) { return Single.create(new SingleAction() { @Override @@ -126,7 +139,7 @@ public class FaviconModel { if (uri == null) { - Bitmap newFavicon = Utils.padFavicon(defaultFavicon); + Bitmap newFavicon = Utils.padFavicon(getDefaultBitmapForCharacter('?')); subscriber.onItem(newFavicon); subscriber.onComplete(); @@ -134,6 +147,9 @@ public class FaviconModel { return; } + Character firstTitleCharacter = !title.isEmpty() ? title.charAt(0) : '?'; + + File faviconCacheFile = createFaviconCacheFile(mApplication, uri); Bitmap favicon = getFaviconFromMemCache(url); @@ -168,7 +184,7 @@ public class FaviconModel { // } // if (favicon == null) { - favicon = defaultFavicon; + favicon = getDefaultBitmapForCharacter(firstTitleCharacter); // } Bitmap newFavicon = Utils.padFavicon(favicon); diff --git a/app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java b/app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java index b447dbd..7668c8e 100644 --- a/app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java +++ b/app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java @@ -537,7 +537,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener, Subscription oldSubscription = mFaviconFetchSubscriptions.get(url); SubscriptionUtils.safeUnsubscribe(oldSubscription); - final Subscription faviconSubscription = mFaviconModel.faviconForUrl(url, mWebpageBitmap, true) + final Subscription faviconSubscription = mFaviconModel.faviconForUrl(url, web.getTitle(), true) .subscribeOn(Schedulers.worker()) .observeOn(Schedulers.main()) .subscribe(new SingleOnSubscribe() { diff --git a/app/src/main/java/acr/browser/lightning/utils/DrawableUtils.java b/app/src/main/java/acr/browser/lightning/utils/DrawableUtils.java index 19e426c..259ce15 100644 --- a/app/src/main/java/acr/browser/lightning/utils/DrawableUtils.java +++ b/app/src/main/java/acr/browser/lightning/utils/DrawableUtils.java @@ -1,7 +1,9 @@ package acr.browser.lightning.utils; +import android.app.Application; import android.graphics.Bitmap; import android.graphics.Canvas; +import android.graphics.Color; import android.graphics.Paint; import android.graphics.PorterDuff; import android.graphics.PorterDuffXfermode; @@ -9,12 +11,17 @@ import android.graphics.RectF; import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.os.Build; +import android.support.annotation.ColorInt; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.v4.content.ContextCompat; import android.view.View; +import acr.browser.lightning.R; + public class DrawableUtils { + @NonNull public static Bitmap getRoundedNumberImage(int number, int width, int height, int color, int thickness) { String text; @@ -56,6 +63,68 @@ public class DrawableUtils { return image; } + /** + * Creates a rounded square of a certain color with + * a character imprinted in white on it. + * + * @param character the character to write on the image. + * @param width the width of the final image. + * @param height the height of the final image. + * @param color the background color of the rounded square. + * @return a valid bitmap of a rounded square with a character on it. + */ + @NonNull + public static Bitmap getRoundedLetterImage(@NonNull Character character, int width, int height, int color) { + Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); + Canvas canvas = new Canvas(image); + Paint paint = new Paint(); + paint.setColor(color); + Typeface boldText = Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD); + paint.setTypeface(boldText); + paint.setTextSize(Utils.dpToPx(14)); + paint.setAntiAlias(true); + paint.setTextAlign(Paint.Align.CENTER); + paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER)); + + int radius = Utils.dpToPx(2); + + RectF outer = new RectF(0, 0, canvas.getWidth(), canvas.getHeight()); + canvas.drawRoundRect(outer, radius, radius, paint); + + int xPos = (canvas.getWidth() / 2); + int yPos = (int) ((canvas.getHeight() / 2) - ((paint.descent() + paint.ascent()) / 2)); + + paint.setColor(Color.WHITE); + canvas.drawText(character.toString(), xPos, yPos, paint); + + return image; + } + + /** + * Hashes a character to one of four colors: + * blue, green, red, or orange. + * + * @param character the character to hash. + * @param app the application needed to get the color. + * @return one of the above colors, or black something goes wrong. + */ + @ColorInt + public static int characterToColorHash(@NonNull Character character, @NonNull Application app) { + int smallHash = Character.getNumericValue(character) % 4; + switch (Math.abs(smallHash)) { + case 0: + return ContextCompat.getColor(app, R.color.bookmark_default_blue); + case 1: + return ContextCompat.getColor(app, R.color.bookmark_default_green); + case 2: + return ContextCompat.getColor(app, R.color.bookmark_default_red); + case 3: + return ContextCompat.getColor(app, R.color.bookmark_default_orange); + default: + return Color.BLACK; + } + } + public static int mixColor(float fraction, int startValue, int endValue) { int startA = (startValue >> 24) & 0xff; diff --git a/app/src/main/res/layout/bookmark_list_item.xml b/app/src/main/res/layout/bookmark_list_item.xml index 17bf88a..874b39f 100644 --- a/app/src/main/res/layout/bookmark_list_item.xml +++ b/app/src/main/res/layout/bookmark_list_item.xml @@ -9,8 +9,8 @@ #F44336 + #2196F3 + #4CAF50 + #EF5350 + #FF9800 + \ No newline at end of file diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 5059ea6..d40476a 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -10,4 +10,6 @@ 8dp 16dp + 24dp + From 954f8c5885fbb24e7e54f3612b6fb32cad6e668f Mon Sep 17 00:00:00 2001 From: anthony restaino Date: Tue, 13 Jun 2017 20:28:28 -0400 Subject: [PATCH 17/56] Referencing controller instead of browser activity --- .../lightning/download/DownloadHandler.java | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/acr/browser/lightning/download/DownloadHandler.java b/app/src/main/java/acr/browser/lightning/download/DownloadHandler.java index 2bc9344..fc53bc6 100644 --- a/app/src/main/java/acr/browser/lightning/download/DownloadHandler.java +++ b/app/src/main/java/acr/browser/lightning/download/DownloadHandler.java @@ -32,10 +32,10 @@ import javax.inject.Inject; import acr.browser.lightning.BuildConfig; import acr.browser.lightning.R; -import acr.browser.lightning.activity.BrowserActivity; import acr.browser.lightning.activity.MainActivity; import acr.browser.lightning.app.BrowserApp; import acr.browser.lightning.constant.Constants; +import acr.browser.lightning.controller.UIController; import acr.browser.lightning.database.downloads.DownloadItem; import acr.browser.lightning.database.downloads.DownloadsModel; import acr.browser.lightning.dialog.BrowserDialog; @@ -81,7 +81,7 @@ public class DownloadHandler { // if we're dealing wih A/V content that's not explicitly marked // for download, check if it's streamable. if (contentDisposition == null - || !contentDisposition.regionMatches(true, 0, "attachment", 0, 10)) { + || !contentDisposition.regionMatches(true, 0, "attachment", 0, 10)) { // query the package manager to see if there's a registered handler // that matches. Intent intent = new Intent(Intent.ACTION_VIEW); @@ -93,12 +93,12 @@ public class DownloadHandler { intent.setSelector(null); } ResolveInfo info = context.getPackageManager().resolveActivity(intent, - PackageManager.MATCH_DEFAULT_ONLY); + PackageManager.MATCH_DEFAULT_ONLY); if (info != null) { // If we resolved to ourselves, we don't want to attempt to // load the url only to try and download it again. if (BuildConfig.APPLICATION_ID.equals(info.activityInfo.packageName) - || MainActivity.class.getName().equals(info.activityInfo.name)) { + || MainActivity.class.getName().equals(info.activityInfo.name)) { // someone (other than us) knows how to handle this mime // type with this scheme, don't download. try { @@ -178,8 +178,8 @@ public class DownloadHandler { } Dialog dialog = new AlertDialog.Builder(context).setTitle(title) - .setIcon(android.R.drawable.ic_dialog_alert).setMessage(msg) - .setPositiveButton(R.string.action_ok, null).show(); + .setIcon(android.R.drawable.ic_dialog_alert).setMessage(msg) + .setPositiveButton(R.string.action_ok, null).show(); BrowserDialog.setDialogSize(context, dialog); return; } @@ -246,7 +246,7 @@ public class DownloadHandler { } else { Log.d(TAG, "Valid mimetype, attempting to download"); final DownloadManager manager = (DownloadManager) context - .getSystemService(Context.DOWNLOAD_SERVICE); + .getSystemService(Context.DOWNLOAD_SERVICE); try { manager.enqueue(request); } catch (IllegalArgumentException e) { @@ -262,18 +262,18 @@ public class DownloadHandler { } // save download in database - BrowserActivity browserActivity = (BrowserActivity) context; + UIController browserActivity = (UIController) context; LightningView view = browserActivity.getTabModel().getCurrentTab(); if (view != null && !view.isIncognito()) { downloadsModel.addDownloadIfNotExists(new DownloadItem(url, filename, contentSize)) - .subscribe(new SingleOnSubscribe() { - @Override - public void onItem(@Nullable Boolean item) { - if (item != null && !item) - Log.i(TAG, "error saving download to database"); - } - }); + .subscribe(new SingleOnSubscribe() { + @Override + public void onItem(@Nullable Boolean item) { + if (item != null && !item) + Log.i(TAG, "error saving download to database"); + } + }); } } From 73136e4b563a0ad39a36f5d2077784165a00254c Mon Sep 17 00:00:00 2001 From: anthony restaino Date: Tue, 13 Jun 2017 21:01:26 -0400 Subject: [PATCH 18/56] Reducing usage of file names --- .../lightning/activity/BrowserActivity.java | 7 ++----- .../lightning/constant/DownloadsPage.java | 11 ++++++----- .../browser/lightning/constant/HistoryPage.java | 16 ++++++++++++++-- .../browser/lightning/constant/StartPage.java | 7 ++++++- .../lightning/dialog/LightningDialogBuilder.java | 3 ++- .../browser/lightning/view/LightningView.java | 7 +++---- 6 files changed, 33 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java b/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java index ff28dff..b83caa9 100644 --- a/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java +++ b/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java @@ -95,7 +95,6 @@ import acr.browser.lightning.browser.BookmarksView; import acr.browser.lightning.browser.BrowserPresenter; import acr.browser.lightning.browser.BrowserView; import acr.browser.lightning.browser.TabsView; -import acr.browser.lightning.constant.BookmarkPage; import acr.browser.lightning.constant.Constants; import acr.browser.lightning.constant.DownloadsPage; import acr.browser.lightning.constant.HistoryPage; @@ -2178,8 +2177,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @Override public void handleBookmarksChange() { final LightningView currentTab = mTabsManager.getCurrentTab(); - if (currentTab != null && currentTab.getUrl().startsWith(Constants.FILE) - && currentTab.getUrl().endsWith(BookmarkPage.FILENAME)) { + if (currentTab != null && UrlUtils.isBookmarkUrl(currentTab.getUrl())) { currentTab.loadBookmarkpage(); } if (currentTab != null) { @@ -2190,8 +2188,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @Override public void handleDownloadDeleted() { final LightningView currentTab = mTabsManager.getCurrentTab(); - if (currentTab != null && currentTab.getUrl().startsWith(Constants.FILE) - && currentTab.getUrl().endsWith(DownloadsPage.FILENAME)) { + if (currentTab != null && UrlUtils.isDownloadsUrl(currentTab.getUrl())) { currentTab.loadDownloadspage(); } if (currentTab != null) { diff --git a/app/src/main/java/acr/browser/lightning/constant/DownloadsPage.java b/app/src/main/java/acr/browser/lightning/constant/DownloadsPage.java index 5e5eb8a..0d5e7da 100644 --- a/app/src/main/java/acr/browser/lightning/constant/DownloadsPage.java +++ b/app/src/main/java/acr/browser/lightning/constant/DownloadsPage.java @@ -56,7 +56,10 @@ public final class DownloadsPage { private static final String END = ""; - private File mFilesDir; + @NonNull + private static File getDownloadsPageFile(@NonNull Application application) { + return new File(application.getFilesDir(), FILENAME); + } @Inject Application mApp; @Inject PreferenceManager mPreferenceManager; @@ -74,11 +77,9 @@ public final class DownloadsPage { return Single.create(new SingleAction() { @Override public void onSubscribe(@NonNull SingleSubscriber subscriber) { - mFilesDir = mApp.getFilesDir(); - buildDownloadsPage(); - File downloadsWebPage = new File(mFilesDir, FILENAME); + File downloadsWebPage = new File(getDownloadsPageFile(mApp), FILENAME); subscriber.onItem(Constants.FILE + downloadsWebPage); subscriber.onComplete(); @@ -120,7 +121,7 @@ public final class DownloadsPage { FileWriter bookWriter = null; try { //noinspection IOResourceOpenedButNotSafelyClosed - bookWriter = new FileWriter(new File(mFilesDir, FILENAME), false); + bookWriter = new FileWriter(getDownloadsPageFile(mApp), false); bookWriter.write(downloadsBuilder.toString()); } catch (IOException e) { e.printStackTrace(); diff --git a/app/src/main/java/acr/browser/lightning/constant/HistoryPage.java b/app/src/main/java/acr/browser/lightning/constant/HistoryPage.java index 0e102ca..e42d83a 100644 --- a/app/src/main/java/acr/browser/lightning/constant/HistoryPage.java +++ b/app/src/main/java/acr/browser/lightning/constant/HistoryPage.java @@ -61,6 +61,18 @@ public class HistoryPage { private static final String END = ""; + /** + * Get the file that the history page is stored in + * or should be stored in. + * + * @param application the application used to access the file. + * @return a valid file object, note that the file might not exist. + */ + @NonNull + private static File getHistoryPageFile(@NonNull Application application) { + return new File(application.getFilesDir(), FILENAME); + } + @NonNull private final String mTitle; @Inject Application mApp; @@ -98,7 +110,7 @@ public class HistoryPage { } historyBuilder.append(END); - File historyWebPage = new File(mApp.getFilesDir(), FILENAME); + File historyWebPage = getHistoryPageFile(mApp); FileWriter historyWriter = null; try { //noinspection IOResourceOpenedButNotSafelyClosed @@ -131,7 +143,7 @@ public class HistoryPage { return Completable.create(new CompletableAction() { @Override public void onSubscribe(@NonNull CompletableSubscriber subscriber) { - File historyWebPage = new File(application.getFilesDir(), FILENAME); + File historyWebPage = getHistoryPageFile(application); if (historyWebPage.exists()) { historyWebPage.delete(); } diff --git a/app/src/main/java/acr/browser/lightning/constant/StartPage.java b/app/src/main/java/acr/browser/lightning/constant/StartPage.java index b422ab1..d35cd2a 100644 --- a/app/src/main/java/acr/browser/lightning/constant/StartPage.java +++ b/app/src/main/java/acr/browser/lightning/constant/StartPage.java @@ -54,6 +54,11 @@ public class StartPage { private static final String END = "\" + document.getElementById(\"search_input\").value;document.getElementById(\"search_input\").value = \"\";}return false;}"; + @NonNull + private static File getStartPageFile(@NonNull Application application) { + return new File(application.getFilesDir(), FILENAME); + } + @NonNull private final String mTitle; @Inject Application mApp; @@ -151,7 +156,7 @@ public class StartPage { homepageBuilder.append(searchUrl); homepageBuilder.append(END); - File homepage = new File(mApp.getFilesDir(), FILENAME); + File homepage = getStartPageFile(mApp); FileWriter hWriter = null; try { //noinspection IOResourceOpenedButNotSafelyClosed diff --git a/app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java b/app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java index 7d7d8eb..c9d70a2 100644 --- a/app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java +++ b/app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java @@ -35,6 +35,7 @@ import acr.browser.lightning.download.DownloadHandler; import acr.browser.lightning.preference.PreferenceManager; import acr.browser.lightning.utils.IntentUtils; import acr.browser.lightning.utils.Preconditions; +import acr.browser.lightning.utils.UrlUtils; /** * TODO Rename this class it doesn't build dialogs only for bookmarks @@ -72,7 +73,7 @@ public class LightningDialogBuilder { @NonNull final UIController uiController, @NonNull final String url) { final HistoryItem item; - if (url.startsWith(Constants.FILE) && url.endsWith(BookmarkPage.FILENAME)) { + if (UrlUtils.isBookmarkUrl(url)) { // TODO hacky, make a better bookmark mechanism in the future final Uri uri = Uri.parse(url); final String filename = uri.getLastPathSegment(); diff --git a/app/src/main/java/acr/browser/lightning/view/LightningView.java b/app/src/main/java/acr/browser/lightning/view/LightningView.java index 8532dea..cf852e9 100644 --- a/app/src/main/java/acr/browser/lightning/view/LightningView.java +++ b/app/src/main/java/acr/browser/lightning/view/LightningView.java @@ -48,7 +48,6 @@ import acr.browser.lightning.app.BrowserApp; import acr.browser.lightning.constant.BookmarkPage; import acr.browser.lightning.constant.Constants; import acr.browser.lightning.constant.DownloadsPage; -import acr.browser.lightning.constant.HistoryPage; import acr.browser.lightning.constant.StartPage; import acr.browser.lightning.controller.UIController; import acr.browser.lightning.dialog.LightningDialogBuilder; @@ -989,21 +988,21 @@ public class LightningView { final WebView.HitTestResult result = mWebView.getHitTestResult(); String currentUrl = mWebView.getUrl(); if (currentUrl != null && UrlUtils.isSpecialUrl(currentUrl)) { - if (currentUrl.endsWith(HistoryPage.FILENAME)) { + if (UrlUtils.isHistoryUrl(currentUrl)) { if (url != null) { mBookmarksDialogBuilder.showLongPressedHistoryLinkDialog(mActivity, mUIController, url); } else if (result != null && result.getExtra() != null) { final String newUrl = result.getExtra(); mBookmarksDialogBuilder.showLongPressedHistoryLinkDialog(mActivity, mUIController, newUrl); } - } else if (currentUrl.endsWith(BookmarkPage.FILENAME)) { + } else if (UrlUtils.isBookmarkUrl(currentUrl)) { if (url != null) { mBookmarksDialogBuilder.showLongPressedDialogForBookmarkUrl(mActivity, mUIController, url); } else if (result != null && result.getExtra() != null) { final String newUrl = result.getExtra(); mBookmarksDialogBuilder.showLongPressedDialogForBookmarkUrl(mActivity, mUIController, newUrl); } - } else if (currentUrl.endsWith(DownloadsPage.FILENAME)) { + } else if (UrlUtils.isDownloadsUrl(currentUrl)) { if (url != null) { mBookmarksDialogBuilder.showLongPressedDialogForDownloadUrl(mActivity, mUIController, url); } else if (result != null && result.getExtra() != null) { From 12a93d208d7a3d660dd401a2cc37519937e16867 Mon Sep 17 00:00:00 2001 From: anthony restaino Date: Tue, 13 Jun 2017 21:25:53 -0400 Subject: [PATCH 19/56] Fixing bug where folders didn't show up on the bookmarks page --- .../lightning/constant/BookmarkPage.java | 109 +++++++++++------- .../lightning/constant/DownloadsPage.java | 2 +- .../lightning/view/LightningWebClient.java | 5 +- 3 files changed, 69 insertions(+), 47 deletions(-) diff --git a/app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java b/app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java index e417932..b0dcea4 100644 --- a/app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java +++ b/app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java @@ -8,6 +8,7 @@ import android.app.Application; import android.graphics.Bitmap; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.text.TextUtils; import com.anthonycr.bonsai.Single; import com.anthonycr.bonsai.SingleAction; @@ -75,8 +76,16 @@ public final class BookmarkPage { private static final String FOLDER_ICON = "folder.png"; - private File mFilesDir; - private File mCacheDir; + @NonNull + private static File getBookmarkPage(@NonNull Application application, @Nullable String folder) { + String prefix = !TextUtils.isEmpty(folder) ? folder + '-' : ""; + return new File(application.getFilesDir(), prefix + FILENAME); + } + + @NonNull + private static File getFaviconFile(@NonNull Application application) { + return new File(application.getCacheDir(), FOLDER_ICON); + } @Inject Application mApp; @Inject BookmarkModel mManager; @@ -95,12 +104,10 @@ public final class BookmarkPage { return Single.create(new SingleAction() { @Override public void onSubscribe(@NonNull SingleSubscriber subscriber) { - mCacheDir = mApp.getCacheDir(); - mFilesDir = mApp.getFilesDir(); cacheDefaultFolderIcon(); buildBookmarkPage(null); - File bookmarkWebPage = new File(mFilesDir, FILENAME); + File bookmarkWebPage = getBookmarkPage(mApp, null); subscriber.onItem(Constants.FILE + bookmarkWebPage); subscriber.onComplete(); @@ -110,9 +117,8 @@ public final class BookmarkPage { private void cacheDefaultFolderIcon() { FileOutputStream outputStream = null; - File image = new File(mCacheDir, FOLDER_ICON); try { - outputStream = new FileOutputStream(image); + outputStream = new FileOutputStream(getFaviconFile(mApp)); mFolderIcon.compress(Bitmap.CompressFormat.PNG, 100, outputStream); mFolderIcon.recycle(); } catch (FileNotFoundException e) { @@ -126,49 +132,64 @@ public final class BookmarkPage { mManager.getBookmarksFromFolderSorted(folder) .subscribe(new SingleOnSubscribe>() { @Override - public void onItem(@Nullable List list) { + public void onItem(@Nullable final List list) { Preconditions.checkNonNull(list); - final File bookmarkWebPage; - if (folder == null || folder.isEmpty()) { - bookmarkWebPage = new File(mFilesDir, FILENAME); + if (folder == null) { + mManager.getFoldersSorted() + .subscribe(new SingleOnSubscribe>() { + @Override + public void onItem(@Nullable List item) { + Preconditions.checkNonNull(item); + + list.addAll(item); + + buildPageHtml(list, null); + } + }); } else { - bookmarkWebPage = new File(mFilesDir, folder + '-' + FILENAME); - } - final StringBuilder bookmarkBuilder = new StringBuilder(HEADING_1 + mTitle + HEADING_2); - - final String folderIconPath = Constants.FILE + mCacheDir + '/' + FOLDER_ICON; - for (int n = 0, size = list.size(); n < size; n++) { - final HistoryItem item = list.get(n); - bookmarkBuilder.append(PART1); - if (item.isFolder()) { - final File folderPage = new File(mFilesDir, item.getTitle() + '-' + FILENAME); - bookmarkBuilder.append(Constants.FILE).append(folderPage); - bookmarkBuilder.append(PART2); - bookmarkBuilder.append(folderIconPath); - buildBookmarkPage(item.getTitle()); - } else { - bookmarkBuilder.append(item.getUrl()); - bookmarkBuilder.append(PART2).append(PART3); - bookmarkBuilder.append(item.getUrl()); - } - bookmarkBuilder.append(PART4); - bookmarkBuilder.append(item.getTitle()); - bookmarkBuilder.append(PART5); - } - bookmarkBuilder.append(END); - FileWriter bookWriter = null; - try { - //noinspection IOResourceOpenedButNotSafelyClosed - bookWriter = new FileWriter(bookmarkWebPage, false); - bookWriter.write(bookmarkBuilder.toString()); - } catch (IOException e) { - e.printStackTrace(); - } finally { - Utils.close(bookWriter); + buildPageHtml(list, folder); } } }); } + private void buildPageHtml(@NonNull List bookmarksAndFolders, @Nullable String folder) { + final File bookmarkWebPage = getBookmarkPage(mApp, folder); + + final StringBuilder bookmarkBuilder = new StringBuilder(HEADING_1 + mTitle + HEADING_2); + + final String folderIconPath = getFaviconFile(mApp).toString(); + + for (int n = 0, size = bookmarksAndFolders.size(); n < size; n++) { + final HistoryItem item = bookmarksAndFolders.get(n); + bookmarkBuilder.append(PART1); + if (item.isFolder()) { + final File folderPage = getBookmarkPage(mApp, item.getTitle()); + bookmarkBuilder.append(Constants.FILE).append(folderPage); + bookmarkBuilder.append(PART2); + bookmarkBuilder.append(folderIconPath); + buildBookmarkPage(item.getTitle()); + } else { + bookmarkBuilder.append(item.getUrl()); + bookmarkBuilder.append(PART2).append(PART3); + bookmarkBuilder.append(item.getUrl()); + } + bookmarkBuilder.append(PART4); + bookmarkBuilder.append(item.getTitle()); + bookmarkBuilder.append(PART5); + } + bookmarkBuilder.append(END); + FileWriter bookWriter = null; + try { + //noinspection IOResourceOpenedButNotSafelyClosed + bookWriter = new FileWriter(bookmarkWebPage, false); + bookWriter.write(bookmarkBuilder.toString()); + } catch (IOException e) { + e.printStackTrace(); + } finally { + Utils.close(bookWriter); + } + } + } diff --git a/app/src/main/java/acr/browser/lightning/constant/DownloadsPage.java b/app/src/main/java/acr/browser/lightning/constant/DownloadsPage.java index 0d5e7da..459ccdc 100644 --- a/app/src/main/java/acr/browser/lightning/constant/DownloadsPage.java +++ b/app/src/main/java/acr/browser/lightning/constant/DownloadsPage.java @@ -79,7 +79,7 @@ public final class DownloadsPage { public void onSubscribe(@NonNull SingleSubscriber subscriber) { buildDownloadsPage(); - File downloadsWebPage = new File(getDownloadsPageFile(mApp), FILENAME); + File downloadsWebPage = getDownloadsPageFile(mApp); subscriber.onItem(Constants.FILE + downloadsWebPage); subscriber.onComplete(); diff --git a/app/src/main/java/acr/browser/lightning/view/LightningWebClient.java b/app/src/main/java/acr/browser/lightning/view/LightningWebClient.java index c40b302..7db2c4d 100644 --- a/app/src/main/java/acr/browser/lightning/view/LightningWebClient.java +++ b/app/src/main/java/acr/browser/lightning/view/LightningWebClient.java @@ -49,6 +49,7 @@ import acr.browser.lightning.utils.AdBlock; import acr.browser.lightning.utils.IntentUtils; import acr.browser.lightning.utils.Preconditions; import acr.browser.lightning.utils.ProxyUtils; +import acr.browser.lightning.utils.UrlUtils; import acr.browser.lightning.utils.Utils; public class LightningWebClient extends WebViewClient { @@ -359,12 +360,12 @@ public class LightningWebClient extends WebViewClient { } return true; } - } else if (url.startsWith(Constants.FILE)) { + } else if (url.startsWith(Constants.FILE) && !UrlUtils.isSpecialUrl(url)) { File file = new File(url.replace(Constants.FILE, "")); if (file.exists()) { String newMimeType = MimeTypeMap.getSingleton() - .getMimeTypeFromExtension(Utils.guessFileExtension(file.toString())); + .getMimeTypeFromExtension(Utils.guessFileExtension(file.toString())); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); From 003954773c01d12d78b185fddabd8a1743fad398 Mon Sep 17 00:00:00 2001 From: anthony restaino Date: Tue, 13 Jun 2017 21:32:37 -0400 Subject: [PATCH 20/56] Switching to URLUtil where possible --- .../lightning/activity/BrowserActivity.java | 4 ++-- .../lightning/activity/TabsManager.java | 22 +++++++++---------- .../lightning/browser/BrowserPresenter.java | 3 ++- .../browser/lightning/constant/Constants.java | 6 ++--- .../fragment/GeneralSettingsFragment.java | 3 ++- .../acr/browser/lightning/utils/Utils.java | 3 ++- .../lightning/view/LightningWebClient.java | 5 +++-- 7 files changed, 25 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java b/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java index b83caa9..625f0e9 100644 --- a/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java +++ b/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java @@ -61,6 +61,7 @@ import android.view.animation.Animation; import android.view.animation.Transformation; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputMethodManager; +import android.webkit.URLUtil; import android.webkit.ValueCallback; import android.webkit.WebChromeClient.CustomViewCallback; import android.webkit.WebIconDatabase; @@ -656,8 +657,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements switch (mPreferences.getSearchChoice()) { case 0: mSearchText = mPreferences.getSearchUrl(); - if (!mSearchText.startsWith(Constants.HTTP) - && !mSearchText.startsWith(Constants.HTTPS)) { + if (!URLUtil.isNetworkUrl(mSearchText)) { mSearchText = Constants.GOOGLE_SEARCH; } break; diff --git a/app/src/main/java/acr/browser/lightning/activity/TabsManager.java b/app/src/main/java/acr/browser/lightning/activity/TabsManager.java index 11ce58c..6e3559d 100644 --- a/app/src/main/java/acr/browser/lightning/activity/TabsManager.java +++ b/app/src/main/java/acr/browser/lightning/activity/TabsManager.java @@ -12,6 +12,7 @@ import android.support.annotation.Nullable; import android.support.v7.app.AlertDialog; import android.text.TextUtils; import android.util.Log; +import android.webkit.URLUtil; import android.webkit.WebView; import com.anthonycr.bonsai.Completable; @@ -32,7 +33,6 @@ import javax.inject.Inject; import acr.browser.lightning.R; import acr.browser.lightning.app.BrowserApp; import acr.browser.lightning.constant.BookmarkPage; -import acr.browser.lightning.constant.Constants; import acr.browser.lightning.constant.DownloadsPage; import acr.browser.lightning.constant.HistoryPage; import acr.browser.lightning.constant.StartPage; @@ -174,15 +174,15 @@ public class TabsManager { }); } else if (UrlUtils.isDownloadsUrl(url)) { new DownloadsPage().getDownloadsPage() - .subscribeOn(Schedulers.io()) - .observeOn(Schedulers.main()) - .subscribe(new SingleOnSubscribe() { - @Override - public void onItem(@Nullable String item) { - Preconditions.checkNonNull(item); - tab.loadUrl(item); - } - }); + .subscribeOn(Schedulers.io()) + .observeOn(Schedulers.main()) + .subscribe(new SingleOnSubscribe() { + @Override + public void onItem(@Nullable String item) { + Preconditions.checkNonNull(item); + tab.loadUrl(item); + } + }); } else if (UrlUtils.isStartPageUrl(url)) { new StartPage().getHomepage() .subscribeOn(Schedulers.io()) @@ -214,7 +214,7 @@ public class TabsManager { @Override public void onComplete() { if (url != null) { - if (url.startsWith(Constants.FILE)) { + if (URLUtil.isFileUrl(url)) { AlertDialog.Builder builder = new AlertDialog.Builder(activity); Dialog dialog = builder.setCancelable(true) .setTitle(R.string.title_warning) diff --git a/app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java b/app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java index 5ccfa72..7c41038 100644 --- a/app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java +++ b/app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java @@ -6,6 +6,7 @@ import android.content.Intent; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.util.Log; +import android.webkit.URLUtil; import com.anthonycr.bonsai.CompletableOnSubscribe; import com.anthonycr.bonsai.Schedulers; @@ -232,7 +233,7 @@ public class BrowserPresenter { tab.loadUrl(url); } } else if (url != null) { - if (url.startsWith(Constants.FILE)) { + if (URLUtil.isFileUrl(url)) { mView.showBlockedLocalFileDialog(new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { diff --git a/app/src/main/java/acr/browser/lightning/constant/Constants.java b/app/src/main/java/acr/browser/lightning/constant/Constants.java index 731d4a5..9644374 100644 --- a/app/src/main/java/acr/browser/lightning/constant/Constants.java +++ b/app/src/main/java/acr/browser/lightning/constant/Constants.java @@ -30,9 +30,9 @@ public final class Constants { public static final String YANDEX_SEARCH = "https://yandex.ru/yandsearch?lr=21411&text="; // Custom local page schemes - public static final String SCHEME_HOMEPAGE = "about:home"; - public static final String SCHEME_BLANK = "about:blank"; - public static final String SCHEME_BOOKMARKS = "about:bookmarks"; + public static final String SCHEME_HOMEPAGE = Constants.ABOUT + "home"; + public static final String SCHEME_BLANK = Constants.ABOUT + "blank"; + public static final String SCHEME_BOOKMARKS = Constants.ABOUT + "bookmarks"; // Miscellaneous JavaScript public static final String JAVASCRIPT_INVERT_PAGE = "javascript:(function(){var e='img {-webkit-filter: invert(100%);'+'-moz-filter: invert(100%);'+'-o-filter: invert(100%);'+'-ms-filter: invert(100%); }',t=document.getElementsByTagName('head')[0],n=document.createElement('style');if(!window.counter){window.counter=1}else{window.counter++;if(window.counter%2==0){var e='html {-webkit-filter: invert(0%); -moz-filter: invert(0%); -o-filter: invert(0%); -ms-filter: invert(0%); }'}}n.type='text/css';if(n.styleSheet){n.styleSheet.cssText=e}else{n.appendChild(document.createTextNode(e))}t.appendChild(n)})();"; diff --git a/app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java b/app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java index 70db8dc..b6627cb 100644 --- a/app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java +++ b/app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java @@ -19,6 +19,7 @@ import android.text.InputFilter; import android.text.TextWatcher; import android.view.LayoutInflater; import android.view.View; +import android.webkit.URLUtil; import android.widget.EditText; import acr.browser.lightning.BuildConfig; @@ -422,7 +423,7 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme private void homePicker() { String currentHomepage; mHomepage = mPreferenceManager.getHomepage(); - if (!mHomepage.startsWith(Constants.ABOUT)) { + if (!URLUtil.isAboutUrl(mHomepage)) { currentHomepage = mHomepage; } else { currentHomepage = "https://www.google.com"; diff --git a/app/src/main/java/acr/browser/lightning/utils/Utils.java b/app/src/main/java/acr/browser/lightning/utils/Utils.java index 8bcbe3d..e780848 100644 --- a/app/src/main/java/acr/browser/lightning/utils/Utils.java +++ b/app/src/main/java/acr/browser/lightning/utils/Utils.java @@ -32,6 +32,7 @@ import android.text.TextUtils; import android.util.DisplayMetrics; import android.util.Log; import android.view.View; +import android.webkit.URLUtil; import android.widget.Toast; import java.io.Closeable; @@ -175,7 +176,7 @@ public final class Utils { public static String getDomainName(@Nullable String url) { if (url == null || url.isEmpty()) return ""; - boolean ssl = url.startsWith(Constants.HTTPS); + boolean ssl = URLUtil.isHttpsUrl(url); int index = url.indexOf('/', 8); if (index != -1) { url = url.substring(0, index); diff --git a/app/src/main/java/acr/browser/lightning/view/LightningWebClient.java b/app/src/main/java/acr/browser/lightning/view/LightningWebClient.java index 7db2c4d..ae959bd 100644 --- a/app/src/main/java/acr/browser/lightning/view/LightningWebClient.java +++ b/app/src/main/java/acr/browser/lightning/view/LightningWebClient.java @@ -22,6 +22,7 @@ import android.view.View; import android.webkit.HttpAuthHandler; import android.webkit.MimeTypeMap; import android.webkit.SslErrorHandler; +import android.webkit.URLUtil; import android.webkit.ValueCallback; import android.webkit.WebResourceRequest; import android.webkit.WebResourceResponse; @@ -305,7 +306,7 @@ public class LightningWebClient extends WebViewClient { // If we are in incognito, immediately load, we don't want the url to leave the app return continueLoadingUrl(view, url, headers); } - if (url.startsWith(Constants.ABOUT)) { + if (URLUtil.isAboutUrl(url)) { // If this is an about page, immediately load, we don't need to leave the app return continueLoadingUrl(view, url, headers); } @@ -360,7 +361,7 @@ public class LightningWebClient extends WebViewClient { } return true; } - } else if (url.startsWith(Constants.FILE) && !UrlUtils.isSpecialUrl(url)) { + } else if (URLUtil.isFileUrl(url) && !UrlUtils.isSpecialUrl(url)) { File file = new File(url.replace(Constants.FILE, "")); if (file.exists()) { From 1a1efc9da623fbb7a80b1e98bdbf2266f7606850 Mon Sep 17 00:00:00 2001 From: anthony restaino Date: Tue, 13 Jun 2017 21:55:27 -0400 Subject: [PATCH 21/56] Getting rid of google favicon fetching and using generated favicon as fallbacks --- .../lightning/constant/BookmarkPage.java | 48 ++++++-- .../lightning/favicon/FaviconModel.java | 57 ++++----- .../lightning/favicon/FaviconUtils.java | 4 +- .../lightning/favicon/ImageFetcher.java | 110 ------------------ .../lightning/fragment/BookmarksFragment.java | 2 +- 5 files changed, 62 insertions(+), 159 deletions(-) delete mode 100644 app/src/main/java/acr/browser/lightning/favicon/ImageFetcher.java diff --git a/app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java b/app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java index b0dcea4..f377df8 100644 --- a/app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java +++ b/app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java @@ -6,6 +6,7 @@ package acr.browser.lightning.constant; import android.app.Activity; import android.app.Application; import android.graphics.Bitmap; +import android.net.Uri; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.text.TextUtils; @@ -28,6 +29,8 @@ import acr.browser.lightning.R; import acr.browser.lightning.app.BrowserApp; import acr.browser.lightning.database.HistoryItem; import acr.browser.lightning.database.bookmark.BookmarkModel; +import acr.browser.lightning.favicon.FaviconModel; +import acr.browser.lightning.favicon.FaviconUtils; import acr.browser.lightning.utils.Preconditions; import acr.browser.lightning.utils.ThemeUtils; import acr.browser.lightning.utils.Utils; @@ -75,6 +78,7 @@ public final class BookmarkPage { private static final String END = ""; private static final String FOLDER_ICON = "folder.png"; + private static final String DEFAULT_ICON = "default.png"; @NonNull private static File getBookmarkPage(@NonNull Application application, @Nullable String folder) { @@ -87,8 +91,14 @@ public final class BookmarkPage { return new File(application.getCacheDir(), FOLDER_ICON); } + @NonNull + private static File getDefaultIconFile(@NonNull Application application) { + return new File(application.getCacheDir(), DEFAULT_ICON); + } + @Inject Application mApp; - @Inject BookmarkModel mManager; + @Inject BookmarkModel mBookmarkModel; + @Inject FaviconModel mFaviconModel; @NonNull private final Bitmap mFolderIcon; @NonNull private final String mTitle; @@ -104,7 +114,8 @@ public final class BookmarkPage { return Single.create(new SingleAction() { @Override public void onSubscribe(@NonNull SingleSubscriber subscriber) { - cacheDefaultFolderIcon(); + cacheIcon(mFolderIcon, getFaviconFile(mApp)); + cacheIcon(mFaviconModel.getDefaultBitmapForString(null), getDefaultIconFile(mApp)); buildBookmarkPage(null); File bookmarkWebPage = getBookmarkPage(mApp, null); @@ -115,12 +126,12 @@ public final class BookmarkPage { }); } - private void cacheDefaultFolderIcon() { + private void cacheIcon(@NonNull Bitmap icon, @NonNull File file) { FileOutputStream outputStream = null; try { - outputStream = new FileOutputStream(getFaviconFile(mApp)); - mFolderIcon.compress(Bitmap.CompressFormat.PNG, 100, outputStream); - mFolderIcon.recycle(); + outputStream = new FileOutputStream(file); + icon.compress(Bitmap.CompressFormat.PNG, 100, outputStream); + icon.recycle(); } catch (FileNotFoundException e) { e.printStackTrace(); } finally { @@ -129,14 +140,14 @@ public final class BookmarkPage { } private void buildBookmarkPage(@Nullable final String folder) { - mManager.getBookmarksFromFolderSorted(folder) + mBookmarkModel.getBookmarksFromFolderSorted(folder) .subscribe(new SingleOnSubscribe>() { @Override public void onItem(@Nullable final List list) { Preconditions.checkNonNull(list); if (folder == null) { - mManager.getFoldersSorted() + mBookmarkModel.getFoldersSorted() .subscribe(new SingleOnSubscribe>() { @Override public void onItem(@Nullable List item) { @@ -171,9 +182,26 @@ public final class BookmarkPage { bookmarkBuilder.append(folderIconPath); buildBookmarkPage(item.getTitle()); } else { + + Uri bookmarkUri = FaviconUtils.safeUri(item.getUrl()); + + String faviconFileUrl; + + if (bookmarkUri != null) { + File faviconFile = FaviconModel.getFaviconCacheFile(mApp, bookmarkUri); + if (!faviconFile.exists()) { + mFaviconModel.cacheFaviconForUrl(mFaviconModel.getDefaultBitmapForString(item.getTitle()), item.getUrl()) + .subscribe(); + } + + faviconFileUrl = Constants.FILE + faviconFile; + } else { + faviconFileUrl = Constants.FILE + getDefaultIconFile(mApp); + } + + bookmarkBuilder.append(item.getUrl()); - bookmarkBuilder.append(PART2).append(PART3); - bookmarkBuilder.append(item.getUrl()); + bookmarkBuilder.append(PART2).append(faviconFileUrl); } bookmarkBuilder.append(PART4); bookmarkBuilder.append(item.getTitle()); diff --git a/app/src/main/java/acr/browser/lightning/favicon/FaviconModel.java b/app/src/main/java/acr/browser/lightning/favicon/FaviconModel.java index 3dbfaad..ecca925 100644 --- a/app/src/main/java/acr/browser/lightning/favicon/FaviconModel.java +++ b/app/src/main/java/acr/browser/lightning/favicon/FaviconModel.java @@ -2,10 +2,13 @@ package acr.browser.lightning.favicon; import android.app.Application; import android.graphics.Bitmap; +import android.graphics.BitmapFactory; import android.net.Uri; import android.support.annotation.ColorInt; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.annotation.WorkerThread; +import android.text.TextUtils; import android.util.Log; import android.util.LruCache; @@ -38,7 +41,7 @@ public class FaviconModel { private static final String TAG = "FaviconModel"; - @NonNull private final ImageFetcher mImageFetcher; + @NonNull private final BitmapFactory.Options mLoaderOptions = new BitmapFactory.Options(); @NonNull private final Application mApplication; @NonNull private final LruCache mFaviconCache = new LruCache((int) FileUtils.megabytesToBytes(1)) { @Override @@ -51,7 +54,6 @@ public class FaviconModel { @Inject FaviconModel(@NonNull Application application) { - mImageFetcher = new ImageFetcher(); mApplication = application; mBookmarkIconSize = mApplication.getResources().getDimensionPixelSize(R.dimen.bookmark_item_icon_size); } @@ -75,10 +77,12 @@ public class FaviconModel { } @NonNull - private Bitmap getDefaultBitmapForCharacter(@NonNull Character character) { - @ColorInt int defaultFaviconColor = DrawableUtils.characterToColorHash(character, mApplication); + public Bitmap getDefaultBitmapForString(@Nullable String title) { + Character firstTitleCharacter = !TextUtils.isEmpty(title) ? title.charAt(0) : '?'; - return DrawableUtils.getRoundedLetterImage(character, + @ColorInt int defaultFaviconColor = DrawableUtils.characterToColorHash(firstTitleCharacter, mApplication); + + return DrawableUtils.getRoundedLetterImage(firstTitleCharacter, mBookmarkIconSize, mBookmarkIconSize, defaultFaviconColor); @@ -109,8 +113,9 @@ public class FaviconModel { * @param uri the URI to use as a unique identifier. * @return a valid cache file. */ + @WorkerThread @NonNull - private static File createFaviconCacheFile(@NonNull Application app, @NonNull Uri uri) { + public static File getFaviconCacheFile(@NonNull Application app, @NonNull Uri uri) { FaviconUtils.assertUriSafe(uri); String hash = String.valueOf(uri.getHost().hashCode()); @@ -122,16 +127,13 @@ public class FaviconModel { * Retrieves the favicon for a URL, * may be from network or cache. * - * @param url The URL that we should retrieve the - * favicon for. - * @param title The title for the web page. - * @param allowGoogleService True to allow grabbing favicons - * from Google, false otherwise. @return an observable that emits a bitmap if one is found, + * @param url The URL that we should retrieve the + * favicon for. + * @param title The title for the web page. */ @NonNull public Single faviconForUrl(@NonNull final String url, - @NonNull final String title, - final boolean allowGoogleService) { + @NonNull final String title) { return Single.create(new SingleAction() { @Override public void onSubscribe(@NonNull SingleSubscriber subscriber) { @@ -139,7 +141,7 @@ public class FaviconModel { if (uri == null) { - Bitmap newFavicon = Utils.padFavicon(getDefaultBitmapForCharacter('?')); + Bitmap newFavicon = Utils.padFavicon(getDefaultBitmapForString(title)); subscriber.onItem(newFavicon); subscriber.onComplete(); @@ -147,25 +149,19 @@ public class FaviconModel { return; } - Character firstTitleCharacter = !title.isEmpty() ? title.charAt(0) : '?'; - - - File faviconCacheFile = createFaviconCacheFile(mApplication, uri); + File faviconCacheFile = getFaviconCacheFile(mApplication, uri); Bitmap favicon = getFaviconFromMemCache(url); if (faviconCacheFile.exists() && favicon == null) { - favicon = mImageFetcher.retrieveFaviconFromCache(faviconCacheFile); + favicon = BitmapFactory.decodeFile(faviconCacheFile.getPath(), mLoaderOptions); if (favicon != null) { addFaviconToMemCache(url, favicon); } } - if (favicon == null) { - // TODO: 6/5/17 figure out if optimistic favicon retrieval should be added back or dropped - // favicon = mImageFetcher.retrieveBitmapFromDomain(uri); - } else { + if (favicon != null) { Bitmap newFavicon = Utils.padFavicon(favicon); subscriber.onItem(newFavicon); @@ -174,18 +170,7 @@ public class FaviconModel { return; } - // if (favicon == null && allowGoogleService) { - // favicon = mImageFetcher.retrieveBitmapFromGoogle(uri); - // } - - // if (favicon != null) { - // addFaviconToMemCache(url, favicon); - // cacheFaviconForUrl(favicon, url).subscribe(); - // } - - // if (favicon == null) { - favicon = getDefaultBitmapForCharacter(firstTitleCharacter); - // } + favicon = getDefaultBitmapForString(title); Bitmap newFavicon = Utils.padFavicon(favicon); @@ -220,7 +205,7 @@ public class FaviconModel { FileOutputStream fos = null; try { - File image = createFaviconCacheFile(mApplication, uri); + File image = getFaviconCacheFile(mApplication, uri); fos = new FileOutputStream(image); favicon.compress(Bitmap.CompressFormat.PNG, 100, fos); fos.flush(); diff --git a/app/src/main/java/acr/browser/lightning/favicon/FaviconUtils.java b/app/src/main/java/acr/browser/lightning/favicon/FaviconUtils.java index a32420b..19cd324 100644 --- a/app/src/main/java/acr/browser/lightning/favicon/FaviconUtils.java +++ b/app/src/main/java/acr/browser/lightning/favicon/FaviconUtils.java @@ -8,9 +8,9 @@ import android.text.TextUtils; /** * Simple utils for favicon fetching. */ -class FaviconUtils { +public class FaviconUtils { @Nullable - static Uri safeUri(@NonNull String url) { + public static Uri safeUri(@NonNull String url) { if (TextUtils.isEmpty(url)) { return null; } diff --git a/app/src/main/java/acr/browser/lightning/favicon/ImageFetcher.java b/app/src/main/java/acr/browser/lightning/favicon/ImageFetcher.java deleted file mode 100644 index 337e408..0000000 --- a/app/src/main/java/acr/browser/lightning/favicon/ImageFetcher.java +++ /dev/null @@ -1,110 +0,0 @@ -package acr.browser.lightning.favicon; - -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.net.Uri; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.util.Log; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; - -import acr.browser.lightning.utils.Utils; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.Response; -import okhttp3.ResponseBody; - -/** - * An image fetcher that creates image - * loading requests on demand. - */ -class ImageFetcher { - - private static final String TAG = "ImageFetcher"; - - @NonNull private final BitmapFactory.Options mLoaderOptions = new BitmapFactory.Options(); - @NonNull private final OkHttpClient mHttpClient = new OkHttpClient(); - - ImageFetcher() {} - - @Nullable - Bitmap retrieveFaviconFromCache(@NonNull File cacheFile) { - return BitmapFactory.decodeFile(cacheFile.getPath(), mLoaderOptions); - } - - @Nullable - Bitmap retrieveBitmapFromDomain(@NonNull Uri uri) { - FaviconUtils.assertUriSafe(uri); - - String faviconUrlGuess = uri.getScheme() + "://" + uri.getHost() + "/favicon.ico"; - - return retrieveBitmapFromUrl(faviconUrlGuess); - } - - @Nullable - Bitmap retrieveBitmapFromGoogle(@NonNull Uri uri) { - FaviconUtils.assertUriSafe(uri); - - String googleFaviconUrl = "https://www.google.com/s2/favicons?domain_url=" + uri.getHost(); - - return retrieveBitmapFromUrl(googleFaviconUrl); - } - - @Nullable - private Bitmap retrieveBitmapFromUrl(@NonNull String url) { - Bitmap icon = null; - - InputStream boundsStream = null; - InputStream iconStream = null; - - try { - mLoaderOptions.inSampleSize = 1; - mLoaderOptions.inJustDecodeBounds = true; - - Request imageRequest = new Request.Builder().url(url).build(); - - Response boundsResponse = mHttpClient.newCall(imageRequest).execute(); - ResponseBody boundsBody = boundsResponse.body(); - - if (boundsBody == null) { - return null; - } - - boundsStream = boundsBody.byteStream(); - - BitmapFactory.decodeStream(boundsStream, null, mLoaderOptions); - - boundsBody.close(); - - int size = Utils.dpToPx(24); - - mLoaderOptions.inSampleSize = Utils.calculateInSampleSize(mLoaderOptions, size, size); - mLoaderOptions.inJustDecodeBounds = false; - - Response imageResponse = mHttpClient.newCall(imageRequest).execute(); - - ResponseBody imageBody = imageResponse.body(); - - if (imageBody == null) { - return null; - } - - iconStream = imageBody.byteStream(); - - icon = BitmapFactory.decodeStream(iconStream, null, mLoaderOptions); - - imageBody.close(); - } catch (IOException exception) { - Log.d(TAG, "Unable to download icon: " + url); - } finally { - Utils.close(boundsStream); - Utils.close(iconStream); - } - - return icon; - } - -} diff --git a/app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java b/app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java index 7668c8e..cf62cec 100644 --- a/app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java +++ b/app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java @@ -537,7 +537,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener, Subscription oldSubscription = mFaviconFetchSubscriptions.get(url); SubscriptionUtils.safeUnsubscribe(oldSubscription); - final Subscription faviconSubscription = mFaviconModel.faviconForUrl(url, web.getTitle(), true) + final Subscription faviconSubscription = mFaviconModel.faviconForUrl(url, web.getTitle()) .subscribeOn(Schedulers.worker()) .observeOn(Schedulers.main()) .subscribe(new SingleOnSubscribe() { From 6f07c8e7daa53c21c8385cf8e99ad3178bd343cb Mon Sep 17 00:00:00 2001 From: anthony restaino Date: Tue, 13 Jun 2017 23:11:44 -0400 Subject: [PATCH 22/56] Adding simple unit tests --- .travis.yml | 3 +- app/build.gradle | 1 + .../lightning/utils/PreconditionsTest.java | 19 +++++++++ .../utils/SubscriptionUtilsTest.java | 41 +++++++++++++++++++ 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 app/src/test/java/acr/browser/lightning/utils/PreconditionsTest.java create mode 100644 app/src/test/java/acr/browser/lightning/utils/SubscriptionUtilsTest.java diff --git a/.travis.yml b/.travis.yml index f575367..66f370d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,4 +18,5 @@ before_install: install: - ./gradlew script: - - ./gradlew assembleDebug --stacktrace + - ./gradlew :app:assembleDebug --stacktrace + - ./gradlew :app:test --stacktrace diff --git a/app/build.gradle b/app/build.gradle index e9ae9f0..be9f680 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -63,6 +63,7 @@ dexcount { } dependencies { + testCompile 'junit:junit:4.12' // support libraries def supportLibVersion = '25.4.0' diff --git a/app/src/test/java/acr/browser/lightning/utils/PreconditionsTest.java b/app/src/test/java/acr/browser/lightning/utils/PreconditionsTest.java new file mode 100644 index 0000000..af4e751 --- /dev/null +++ b/app/src/test/java/acr/browser/lightning/utils/PreconditionsTest.java @@ -0,0 +1,19 @@ +package acr.browser.lightning.utils; + +import org.junit.Test; + +/** + * Unit tests for {@link Preconditions}. + */ +public class PreconditionsTest { + + @Test(expected = RuntimeException.class) + public void checkNonNull_Null_ThrowsException() { + Preconditions.checkNonNull(null); + } + + @Test + public void checkNonNull_NonNull_Succeeds() { + Preconditions.checkNonNull(new Object()); + } +} \ No newline at end of file diff --git a/app/src/test/java/acr/browser/lightning/utils/SubscriptionUtilsTest.java b/app/src/test/java/acr/browser/lightning/utils/SubscriptionUtilsTest.java new file mode 100644 index 0000000..7f23232 --- /dev/null +++ b/app/src/test/java/acr/browser/lightning/utils/SubscriptionUtilsTest.java @@ -0,0 +1,41 @@ +package acr.browser.lightning.utils; + +import com.anthonycr.bonsai.Subscription; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Unit tests for {@link SubscriptionUtils}. + */ +public class SubscriptionUtilsTest { + + @Test + public void safeUnsubscribe_NullSubscription_Succeeds() { + SubscriptionUtils.safeUnsubscribe(null); + } + + @Test + public void safeUnsubscribe_NonNullSubscription_SuccessfullyUnsubscribes() { + Subscription subscription = new Subscription() { + + boolean isUnsubscribed = false; + + @Override + public void unsubscribe() { + isUnsubscribed = true; + } + + @Override + public boolean isUnsubscribed() { + return isUnsubscribed; + } + }; + + Assert.assertFalse(subscription.isUnsubscribed()); + + SubscriptionUtils.safeUnsubscribe(subscription); + + Assert.assertTrue(subscription.isUnsubscribed()); + } +} \ No newline at end of file From 3b24f2ec18ec4cd76ee6fa137e13347edbad0788 Mon Sep 17 00:00:00 2001 From: t61p Date: Wed, 14 Jun 2017 16:04:24 +0900 Subject: [PATCH 23/56] Japanese translation update --- app/src/main/res/values-ja/strings.xml | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 59bca81..7560a81 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -1,24 +1,12 @@ - - - + Lightning 新しいタブ 共有 履歴 ブックマーク + ダウンロード ブックマークに追加 ページの URL をコピー 進む @@ -70,6 +58,7 @@ 検索エンジン OK このファイルをダウンロードしますか? (%1$s) + サイズ不明 キャンセル 警告 Adobe Flash Player が見つかりません\nFlash Player をインストールしてください @@ -139,11 +128,13 @@ 許可する 許可しない サインイン + サーバー メッセージ: %s ユーザー名 パスワード 検索候補表示 Google を使用する DuckDuckGo を使用する + Baidu を使用する 検索候補を表示しない HTTP プロキシ @@ -185,6 +176,7 @@ ブックマークをエクスポートする ブックマークをインポートする ブックマークをエクスポートしました + ブックマークのエクスポートに失敗しました! ブックマーク ブックマークのインポートに失敗しました ファイルを選択してください @@ -213,6 +205,7 @@ 色を反転する ダーク + ステータスバーを暗色にする タブ アプリのテーマ ライト @@ -234,6 +227,9 @@ ホーム画面に追加 ホーム画面にショートカットを追加しました すべてのブックマークを削除する + このシステムは Flash Player をサポートしていません + 広告をブロックするには Lightning Plus へアップグレードしてください + このファイルは存在しません FAQ よくある質問と回答 @@ -255,4 +251,6 @@ フォルダ名を変更する フォルダを削除する タブの消去 + ダウンロードの削除 + ダウンロードの全削除 From b9bbeeee7bbc9d45476cdbda619a4f2f4bd29065 Mon Sep 17 00:00:00 2001 From: anthony restaino Date: Wed, 14 Jun 2017 20:49:41 -0400 Subject: [PATCH 24/56] Fixing twitter URL --- app/src/main/res/raw/default_bookmarks.dat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/raw/default_bookmarks.dat b/app/src/main/res/raw/default_bookmarks.dat index ec6722a..3d35ddb 100644 --- a/app/src/main/res/raw/default_bookmarks.dat +++ b/app/src/main/res/raw/default_bookmarks.dat @@ -1,5 +1,5 @@ {"url": "https://twitter.com/RestainoAnthony", "title": "Contact Me", "folder": "", "order": 0} {"url": "https://www.facebook.com/", "title": "Facebook", "folder": "", "order": 1} -{"url": "https://twitter.com", "title": "Twitter", "folder": "", "order": 2} +{"url": "https://twitter.com/", "title": "Twitter", "folder": "", "order": 2} {"url": "https://www.google.com/", "title": "Google", "folder": "", "order": 3} {"url": "https://www.wikipedia.org/", "title": "Wikipedia", "folder": "", "order": 4} From fdc27cced257eb763264bae05581c9215f62b1dc Mon Sep 17 00:00:00 2001 From: anthony restaino Date: Wed, 14 Jun 2017 21:22:09 -0400 Subject: [PATCH 25/56] Naming dialog builder field correctly --- .../browser/lightning/view/LightningView.java | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/acr/browser/lightning/view/LightningView.java b/app/src/main/java/acr/browser/lightning/view/LightningView.java index cf852e9..69b57b5 100644 --- a/app/src/main/java/acr/browser/lightning/view/LightningView.java +++ b/app/src/main/java/acr/browser/lightning/view/LightningView.java @@ -105,7 +105,7 @@ public class LightningView { @NonNull private final Map mRequestHeaders = new ArrayMap<>(); @Inject PreferenceManager mPreferences; - @Inject LightningDialogBuilder mBookmarksDialogBuilder; + @Inject LightningDialogBuilder mDialogBuilder; @Inject ProxyUtils mProxyUtils; public LightningView(@NonNull Activity activity, @Nullable String url, boolean isIncognito) { @@ -249,15 +249,15 @@ public class LightningView { */ public void loadDownloadspage() { new DownloadsPage().getDownloadsPage() - .subscribeOn(Schedulers.io()) - .observeOn(Schedulers.main()) - .subscribe(new SingleOnSubscribe() { - @Override - public void onItem(@Nullable String item) { - Preconditions.checkNonNull(item); - loadUrl(item); - } - }); + .subscribeOn(Schedulers.io()) + .observeOn(Schedulers.main()) + .subscribe(new SingleOnSubscribe() { + @Override + public void onItem(@Nullable String item) { + Preconditions.checkNonNull(item); + loadUrl(item); + } + }); } /** @@ -990,43 +990,43 @@ public class LightningView { if (currentUrl != null && UrlUtils.isSpecialUrl(currentUrl)) { if (UrlUtils.isHistoryUrl(currentUrl)) { if (url != null) { - mBookmarksDialogBuilder.showLongPressedHistoryLinkDialog(mActivity, mUIController, url); + mDialogBuilder.showLongPressedHistoryLinkDialog(mActivity, mUIController, url); } else if (result != null && result.getExtra() != null) { final String newUrl = result.getExtra(); - mBookmarksDialogBuilder.showLongPressedHistoryLinkDialog(mActivity, mUIController, newUrl); + mDialogBuilder.showLongPressedHistoryLinkDialog(mActivity, mUIController, newUrl); } } else if (UrlUtils.isBookmarkUrl(currentUrl)) { if (url != null) { - mBookmarksDialogBuilder.showLongPressedDialogForBookmarkUrl(mActivity, mUIController, url); + mDialogBuilder.showLongPressedDialogForBookmarkUrl(mActivity, mUIController, url); } else if (result != null && result.getExtra() != null) { final String newUrl = result.getExtra(); - mBookmarksDialogBuilder.showLongPressedDialogForBookmarkUrl(mActivity, mUIController, newUrl); + mDialogBuilder.showLongPressedDialogForBookmarkUrl(mActivity, mUIController, newUrl); } } else if (UrlUtils.isDownloadsUrl(currentUrl)) { if (url != null) { - mBookmarksDialogBuilder.showLongPressedDialogForDownloadUrl(mActivity, mUIController, url); + mDialogBuilder.showLongPressedDialogForDownloadUrl(mActivity, mUIController, url); } else if (result != null && result.getExtra() != null) { final String newUrl = result.getExtra(); - mBookmarksDialogBuilder.showLongPressedDialogForDownloadUrl(mActivity, mUIController, newUrl); + mDialogBuilder.showLongPressedDialogForDownloadUrl(mActivity, mUIController, newUrl); } } } else { if (url != null) { if (result != null) { if (result.getType() == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE || result.getType() == WebView.HitTestResult.IMAGE_TYPE) { - mBookmarksDialogBuilder.showLongPressImageDialog(mActivity, mUIController, url, getUserAgent()); + mDialogBuilder.showLongPressImageDialog(mActivity, mUIController, url, getUserAgent()); } else { - mBookmarksDialogBuilder.showLongPressLinkDialog(mActivity, mUIController, url); + mDialogBuilder.showLongPressLinkDialog(mActivity, mUIController, url); } } else { - mBookmarksDialogBuilder.showLongPressLinkDialog(mActivity, mUIController, url); + mDialogBuilder.showLongPressLinkDialog(mActivity, mUIController, url); } } else if (result != null && result.getExtra() != null) { final String newUrl = result.getExtra(); if (result.getType() == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE || result.getType() == WebView.HitTestResult.IMAGE_TYPE) { - mBookmarksDialogBuilder.showLongPressImageDialog(mActivity, mUIController, newUrl, getUserAgent()); + mDialogBuilder.showLongPressImageDialog(mActivity, mUIController, newUrl, getUserAgent()); } else { - mBookmarksDialogBuilder.showLongPressLinkDialog(mActivity, mUIController, newUrl); + mDialogBuilder.showLongPressLinkDialog(mActivity, mUIController, newUrl); } } } From 5bbcec82085fabb65415d3d202cc34d2dbd71f7b Mon Sep 17 00:00:00 2001 From: anthony restaino Date: Wed, 14 Jun 2017 22:06:08 -0400 Subject: [PATCH 26/56] Adding todo around bookmark long press bug --- .../acr/browser/lightning/dialog/LightningDialogBuilder.java | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java b/app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java index c9d70a2..5654b68 100644 --- a/app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java +++ b/app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java @@ -91,6 +91,7 @@ public class LightningDialogBuilder { .subscribe(new SingleOnSubscribe() { @Override public void onItem(@Nullable HistoryItem historyItem) { + // TODO: 6/14/17 figure out solution to case where slashes get appended to root urls causing the item to be null if (historyItem != null) { showLongPressedDialogForBookmarkUrl(activity, uiController, historyItem); } From 33f205d557e2ead7829a3547a5a6972d21568793 Mon Sep 17 00:00:00 2001 From: anthony restaino Date: Wed, 14 Jun 2017 22:13:34 -0400 Subject: [PATCH 27/56] Adding todo and switching to compat interpolator --- .../lightning/dialog/LightningDialogBuilder.java | 2 +- .../interpolator/BezierDecelerateInterpolator.java | 10 ++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java b/app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java index 5654b68..600d65a 100644 --- a/app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java +++ b/app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java @@ -91,7 +91,7 @@ public class LightningDialogBuilder { .subscribe(new SingleOnSubscribe() { @Override public void onItem(@Nullable HistoryItem historyItem) { - // TODO: 6/14/17 figure out solution to case where slashes get appended to root urls causing the item to be null + // TODO: 6/14/17 figure out solution to case where slashes get appended to root urls causing the item to be null if (historyItem != null) { showLongPressedDialogForBookmarkUrl(activity, uiController, historyItem); } diff --git a/app/src/main/java/acr/browser/lightning/interpolator/BezierDecelerateInterpolator.java b/app/src/main/java/acr/browser/lightning/interpolator/BezierDecelerateInterpolator.java index 5ee0a3e..9756f8b 100644 --- a/app/src/main/java/acr/browser/lightning/interpolator/BezierDecelerateInterpolator.java +++ b/app/src/main/java/acr/browser/lightning/interpolator/BezierDecelerateInterpolator.java @@ -1,10 +1,8 @@ package acr.browser.lightning.interpolator; -import android.os.Build; import android.support.annotation.NonNull; -import android.view.animation.DecelerateInterpolator; +import android.support.v4.view.animation.PathInterpolatorCompat; import android.view.animation.Interpolator; -import android.view.animation.PathInterpolator; /** * Bezier decelerate curve similar to iOS. @@ -17,11 +15,7 @@ public class BezierDecelerateInterpolator implements Interpolator { private static final Interpolator PATH_INTERPOLATOR; static { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - PATH_INTERPOLATOR = new PathInterpolator(0.25f, 0.1f, 0.25f, 1); - } else { - PATH_INTERPOLATOR = new DecelerateInterpolator(); - } + PATH_INTERPOLATOR = PathInterpolatorCompat.create(0.25f, 0.1f, 0.25f, 1); } @Override From bb7ec7fd3fae10c82d25c597b42796b567fd7c1b Mon Sep 17 00:00:00 2001 From: anthony restaino Date: Wed, 14 Jun 2017 22:50:05 -0400 Subject: [PATCH 28/56] Switching to IO scheduler and cleaning up cache method --- .../lightning/constant/BookmarkPage.java | 4 +- .../lightning/fragment/BookmarksFragment.java | 2 +- .../lightning/view/LightningChromeClient.java | 40 ++++++++----------- 3 files changed, 20 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java b/app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java index f377df8..9a78c3f 100644 --- a/app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java +++ b/app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java @@ -190,8 +190,8 @@ public final class BookmarkPage { if (bookmarkUri != null) { File faviconFile = FaviconModel.getFaviconCacheFile(mApp, bookmarkUri); if (!faviconFile.exists()) { - mFaviconModel.cacheFaviconForUrl(mFaviconModel.getDefaultBitmapForString(item.getTitle()), item.getUrl()) - .subscribe(); + Bitmap defaultFavicon = mFaviconModel.getDefaultBitmapForString(item.getTitle()); + mFaviconModel.cacheFaviconForUrl(defaultFavicon, item.getUrl()).subscribe(); } faviconFileUrl = Constants.FILE + faviconFile; diff --git a/app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java b/app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java index cf62cec..f998eaa 100644 --- a/app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java +++ b/app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java @@ -538,7 +538,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener, SubscriptionUtils.safeUnsubscribe(oldSubscription); final Subscription faviconSubscription = mFaviconModel.faviconForUrl(url, web.getTitle()) - .subscribeOn(Schedulers.worker()) + .subscribeOn(Schedulers.io()) .observeOn(Schedulers.main()) .subscribe(new SingleOnSubscribe() { @Override diff --git a/app/src/main/java/acr/browser/lightning/view/LightningChromeClient.java b/app/src/main/java/acr/browser/lightning/view/LightningChromeClient.java index 80f40bc..020813a 100644 --- a/app/src/main/java/acr/browser/lightning/view/LightningChromeClient.java +++ b/app/src/main/java/acr/browser/lightning/view/LightningChromeClient.java @@ -73,15 +73,9 @@ public class LightningChromeClient extends WebChromeClient { return; } - Uri uri = Uri.parse(url); - - if (uri.getHost() == null) { - return; - } - mFaviconModel.cacheFaviconForUrl(icon, url) - .subscribeOn(Schedulers.io()) - .subscribe(); + .subscribeOn(Schedulers.io()) + .subscribe(); } @@ -114,21 +108,21 @@ public class LightningChromeClient extends WebChromeClient { org = origin; } builder.setMessage(org + mActivity.getString(R.string.message_location)) - .setCancelable(true) - .setPositiveButton(mActivity.getString(R.string.action_allow), - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int id) { - callback.invoke(origin, true, remember); - } - }) - .setNegativeButton(mActivity.getString(R.string.action_dont_allow), - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int id) { - callback.invoke(origin, false, remember); - } - }); + .setCancelable(true) + .setPositiveButton(mActivity.getString(R.string.action_allow), + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int id) { + callback.invoke(origin, true, remember); + } + }) + .setNegativeButton(mActivity.getString(R.string.action_dont_allow), + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int id) { + callback.invoke(origin, false, remember); + } + }); AlertDialog alert = builder.create(); alert.show(); BrowserDialog.setDialogSize(mActivity, alert); From fa2a7f039bb52bbe2639ccbecc1331d3991b36e9 Mon Sep 17 00:00:00 2001 From: anthony restaino Date: Wed, 14 Jun 2017 23:08:59 -0400 Subject: [PATCH 29/56] Synchronizing access to database --- .../browser/lightning/database/bookmark/BookmarkDatabase.java | 2 +- .../browser/lightning/database/downloads/DownloadsDatabase.java | 2 +- .../acr/browser/lightning/database/history/HistoryDatabase.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/acr/browser/lightning/database/bookmark/BookmarkDatabase.java b/app/src/main/java/acr/browser/lightning/database/bookmark/BookmarkDatabase.java index bb3b929..ed66526 100644 --- a/app/src/main/java/acr/browser/lightning/database/bookmark/BookmarkDatabase.java +++ b/app/src/main/java/acr/browser/lightning/database/bookmark/BookmarkDatabase.java @@ -75,7 +75,7 @@ public class BookmarkDatabase extends SQLiteOpenHelper implements BookmarkModel */ @WorkerThread @NonNull - private SQLiteDatabase lazyDatabase() { + private synchronized SQLiteDatabase lazyDatabase() { if (mDatabase == null || !mDatabase.isOpen()) { mDatabase = getWritableDatabase(); } diff --git a/app/src/main/java/acr/browser/lightning/database/downloads/DownloadsDatabase.java b/app/src/main/java/acr/browser/lightning/database/downloads/DownloadsDatabase.java index a14faff..895205f 100644 --- a/app/src/main/java/acr/browser/lightning/database/downloads/DownloadsDatabase.java +++ b/app/src/main/java/acr/browser/lightning/database/downloads/DownloadsDatabase.java @@ -68,7 +68,7 @@ public class DownloadsDatabase extends SQLiteOpenHelper implements DownloadsMode */ @WorkerThread @NonNull - private SQLiteDatabase lazyDatabase() { + private synchronized SQLiteDatabase lazyDatabase() { if (mDatabase == null || !mDatabase.isOpen()) { mDatabase = getWritableDatabase(); } diff --git a/app/src/main/java/acr/browser/lightning/database/history/HistoryDatabase.java b/app/src/main/java/acr/browser/lightning/database/history/HistoryDatabase.java index b61fa16..8ceab08 100644 --- a/app/src/main/java/acr/browser/lightning/database/history/HistoryDatabase.java +++ b/app/src/main/java/acr/browser/lightning/database/history/HistoryDatabase.java @@ -92,7 +92,7 @@ public class HistoryDatabase extends SQLiteOpenHelper implements HistoryModel { @WorkerThread @NonNull - private SQLiteDatabase lazyDatabase() { + private synchronized SQLiteDatabase lazyDatabase() { if (mDatabase == null || !mDatabase.isOpen()) { mDatabase = this.getWritableDatabase(); } From eed6866113105f9d4c125562e826ce35bcf02629 Mon Sep 17 00:00:00 2001 From: anthony restaino Date: Thu, 15 Jun 2017 23:12:48 -0400 Subject: [PATCH 30/56] Fixing bug where last tab would be destroyed on exit in certain cases --- .../lightning/browser/BrowserPresenter.java | 21 +++++++++++++++++-- .../lightning/constant/BookmarkPage.java | 2 +- .../browser/lightning/constant/StartPage.java | 2 +- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java b/app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java index 7c41038..691d742 100644 --- a/app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java +++ b/app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java @@ -1,6 +1,7 @@ package acr.browser.lightning.browser; import android.app.Activity; +import android.app.Application; import android.content.DialogInterface; import android.content.Intent; import android.support.annotation.NonNull; @@ -17,7 +18,9 @@ import acr.browser.lightning.BuildConfig; import acr.browser.lightning.R; import acr.browser.lightning.activity.TabsManager; import acr.browser.lightning.app.BrowserApp; +import acr.browser.lightning.constant.BookmarkPage; import acr.browser.lightning.constant.Constants; +import acr.browser.lightning.constant.StartPage; import acr.browser.lightning.controller.UIController; import acr.browser.lightning.preference.PreferenceManager; @@ -34,6 +37,7 @@ public class BrowserPresenter { private static final String TAG = "BrowserPresenter"; @NonNull private final TabsManager mTabsModel; + @Inject Application mApplication; @Inject PreferenceManager mPreferences; @NonNull private final BrowserView mView; @@ -144,6 +148,19 @@ public class BrowserPresenter { } + @NonNull + private String mapHomepageToCurrentUrl() { + String homepage = mPreferences.getHomepage(); + switch (homepage) { + case Constants.SCHEME_HOMEPAGE: + return Constants.FILE + StartPage.getStartPageFile(mApplication); + case Constants.SCHEME_BOOKMARKS: + return Constants.FILE + BookmarkPage.getBookmarkPage(mApplication, null); + default: + return homepage; + } + } + /** * Deletes the tab at the specified position. * @@ -166,8 +183,8 @@ public class BrowserPresenter { boolean shouldClose = mShouldClose && isShown && tabToDelete.isNewTab(); final LightningView currentTab = mTabsModel.getCurrentTab(); if (mTabsModel.size() == 1 && currentTab != null && - (UrlUtils.isStartPageUrl(currentTab.getUrl()) || - currentTab.getUrl().equals(mPreferences.getHomepage()))) { + URLUtil.isFileUrl(currentTab.getUrl()) && + currentTab.getUrl().equals(mapHomepageToCurrentUrl())) { mView.closeActivity(); return; } else { diff --git a/app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java b/app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java index 9a78c3f..4742801 100644 --- a/app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java +++ b/app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java @@ -81,7 +81,7 @@ public final class BookmarkPage { private static final String DEFAULT_ICON = "default.png"; @NonNull - private static File getBookmarkPage(@NonNull Application application, @Nullable String folder) { + public static File getBookmarkPage(@NonNull Application application, @Nullable String folder) { String prefix = !TextUtils.isEmpty(folder) ? folder + '-' : ""; return new File(application.getFilesDir(), prefix + FILENAME); } diff --git a/app/src/main/java/acr/browser/lightning/constant/StartPage.java b/app/src/main/java/acr/browser/lightning/constant/StartPage.java index d35cd2a..5bb1a63 100644 --- a/app/src/main/java/acr/browser/lightning/constant/StartPage.java +++ b/app/src/main/java/acr/browser/lightning/constant/StartPage.java @@ -55,7 +55,7 @@ public class StartPage { private static final String END = "\" + document.getElementById(\"search_input\").value;document.getElementById(\"search_input\").value = \"\";}return false;}"; @NonNull - private static File getStartPageFile(@NonNull Application application) { + public static File getStartPageFile(@NonNull Application application) { return new File(application.getFilesDir(), FILENAME); } From 50ca625027f422b5d002c3d78e8fc2b43cbe6019 Mon Sep 17 00:00:00 2001 From: DF1E Date: Fri, 16 Jun 2017 19:00:49 +0200 Subject: [PATCH 31/56] udpate downloads design --- .../lightning/constant/DownloadsPage.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/acr/browser/lightning/constant/DownloadsPage.java b/app/src/main/java/acr/browser/lightning/constant/DownloadsPage.java index 459ccdc..119c676 100644 --- a/app/src/main/java/acr/browser/lightning/constant/DownloadsPage.java +++ b/app/src/main/java/acr/browser/lightning/constant/DownloadsPage.java @@ -6,6 +6,7 @@ package acr.browser.lightning.constant; import android.app.Application; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.util.Log; import com.anthonycr.bonsai.Single; import com.anthonycr.bonsai.SingleAction; @@ -29,9 +30,8 @@ import acr.browser.lightning.utils.Utils; public final class DownloadsPage { - /** - * The download page standard suffix - */ + private static final String TAG = "DownloadsPage"; + public static final String FILENAME = "downloads.html"; private static final String HEADING_1 = "\n" + @@ -41,10 +41,12 @@ public final class DownloadsPage { "\n" + ""; - private static final String HEADING_2 = "" + - "" + - "" + - "

"; + private static final String HEADING_2 = "
"; private static final String PART1 = "
findBookmarkForUrl(@NonNull final String url) { return Single.create(new SingleAction() { @Override public void onSubscribe(@NonNull SingleSubscriber subscriber) { - Cursor cursor = lazyDatabase().query(TABLE_BOOKMARK, null, KEY_URL + "=?", new String[]{url}, null, null, null, "1"); + Cursor cursor = queryWithOptionalEndSlash(url); if (cursor.moveToFirst()) { subscriber.onItem(bindCursorToHistoryItem(cursor)); @@ -168,7 +269,7 @@ public class BookmarkDatabase extends SQLiteOpenHelper implements BookmarkModel return Single.create(new SingleAction() { @Override public void onSubscribe(@NonNull SingleSubscriber subscriber) { - Cursor cursor = lazyDatabase().query(TABLE_BOOKMARK, null, KEY_URL + "=?", new String[]{url}, null, null, null, "1"); + Cursor cursor = queryWithOptionalEndSlash(url); subscriber.onItem(cursor.moveToFirst()); @@ -184,7 +285,7 @@ public class BookmarkDatabase extends SQLiteOpenHelper implements BookmarkModel return Single.create(new SingleAction() { @Override public void onSubscribe(@NonNull SingleSubscriber subscriber) { - Cursor cursor = lazyDatabase().query(TABLE_BOOKMARK, null, KEY_URL + "=?", new String[]{item.getUrl()}, null, null, null, "1"); + Cursor cursor = queryWithOptionalEndSlash(item.getUrl()); if (cursor.moveToFirst()) { cursor.close(); @@ -229,7 +330,7 @@ public class BookmarkDatabase extends SQLiteOpenHelper implements BookmarkModel return Single.create(new SingleAction() { @Override public void onSubscribe(@NonNull SingleSubscriber subscriber) { - int rows = lazyDatabase().delete(TABLE_BOOKMARK, KEY_URL + "=?", new String[]{bookmark.getUrl()}); + int rows = deleteWithOptionalEndSlash(bookmark.getUrl()); subscriber.onItem(rows > 0); subscriber.onComplete(); @@ -290,7 +391,7 @@ public class BookmarkDatabase extends SQLiteOpenHelper implements BookmarkModel } ContentValues contentValues = bindBookmarkToContentValues(newBookmark); - lazyDatabase().update(TABLE_BOOKMARK, contentValues, KEY_URL + "=?", new String[]{oldBookmark.getUrl()}); + updateWithOptionalEndSlash(oldBookmark.getUrl(), contentValues); subscriber.onComplete(); } From fe7dc75973ee9fc612da3ef00aaabf821b7aac6b Mon Sep 17 00:00:00 2001 From: anthony restaino Date: Sat, 17 Jun 2017 11:29:25 -0400 Subject: [PATCH 35/56] Unit tests for StringBuilderUtils, fixing trim method in StringBuilderUtils --- .../lightning/utils/StringBuilderUtils.java | 6 +- .../utils/StringBuilderUtilsTest.java | 118 ++++++++++++++++++ 2 files changed, 121 insertions(+), 3 deletions(-) create mode 100644 app/src/test/java/acr/browser/lightning/utils/StringBuilderUtilsTest.java diff --git a/app/src/main/java/acr/browser/lightning/utils/StringBuilderUtils.java b/app/src/main/java/acr/browser/lightning/utils/StringBuilderUtils.java index 3b2e565..0c66f8a 100644 --- a/app/src/main/java/acr/browser/lightning/utils/StringBuilderUtils.java +++ b/app/src/main/java/acr/browser/lightning/utils/StringBuilderUtils.java @@ -14,8 +14,8 @@ public class StringBuilderUtils { private static final String EMPTY = ""; /** - * Replace a string in a string - * builder with another string. + * Replace the first string found in a + * string builder with another string. * * @param stringBuilder the string builder. * @param toReplace the string to replace. @@ -42,7 +42,7 @@ public class StringBuilderUtils { stringBuilder.replace(0, 1, EMPTY); } - while (stringBuilder.lastIndexOf(SPACE) == (stringBuilder.length() - 1)) { + while (stringBuilder.lastIndexOf(SPACE) == (stringBuilder.length() - 1) && stringBuilder.length() > 0) { stringBuilder.replace(stringBuilder.length() - 1, stringBuilder.length(), EMPTY); } } diff --git a/app/src/test/java/acr/browser/lightning/utils/StringBuilderUtilsTest.java b/app/src/test/java/acr/browser/lightning/utils/StringBuilderUtilsTest.java new file mode 100644 index 0000000..2296162 --- /dev/null +++ b/app/src/test/java/acr/browser/lightning/utils/StringBuilderUtilsTest.java @@ -0,0 +1,118 @@ +package acr.browser.lightning.utils; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Tests for {@link StringBuilderUtils}. + */ +public class StringBuilderUtilsTest { + + @Test + public void replace_SingleCharacter() { + StringBuilder stringBuilder = new StringBuilder("abbbaacccda"); + StringBuilderUtils.replace(stringBuilder, "a", ""); + Assert.assertEquals(stringBuilder.toString(), "bbbaacccda"); + } + + @Test + public void replace_MultipleCharacters() { + StringBuilder stringBuilder = new StringBuilder("___ab___cd___"); + StringBuilderUtils.replace(stringBuilder, "___", "---"); + Assert.assertEquals(stringBuilder.toString(), "---ab___cd___"); + } + + @Test + public void trim_LeadingAndTrailingSpaces() { + StringBuilder stringBuilder = new StringBuilder(" t e s t "); + StringBuilderUtils.trim(stringBuilder); + Assert.assertEquals(stringBuilder.toString(), "t e s t"); + } + + @Test + public void trim_OnlyContainsSpaces() { + StringBuilder stringBuilder = new StringBuilder(" "); + Assert.assertFalse(stringBuilder.toString().isEmpty()); + StringBuilderUtils.trim(stringBuilder); + Assert.assertTrue(stringBuilder.toString().isEmpty()); + } + + @Test + public void isEmpty_HasNoCharacters() { + StringBuilder stringBuilder = new StringBuilder(""); + Assert.assertTrue(StringBuilderUtils.isEmpty(stringBuilder)); + } + + @Test + public void isEmpty_HasCharacters() { + // Case with normal letters + StringBuilder stringBuilder = new StringBuilder("abcdefg"); + Assert.assertFalse(StringBuilderUtils.isEmpty(stringBuilder)); + + // Case with empty spaces + StringBuilder stringBuilder1 = new StringBuilder(" "); + Assert.assertFalse(StringBuilderUtils.isEmpty(stringBuilder1)); + } + + @Test + public void startsWith_SingleCharacter() { + StringBuilder stringBuilder = new StringBuilder("1234567890"); + Assert.assertTrue(StringBuilderUtils.startsWith(stringBuilder, "1")); + Assert.assertFalse(StringBuilderUtils.startsWith(stringBuilder, "2")); + } + + @Test + public void startsWith_MultipleCharacters() { + StringBuilder stringBuilder = new StringBuilder("1234567890"); + Assert.assertTrue(StringBuilderUtils.startsWith(stringBuilder, "12345")); + Assert.assertFalse(StringBuilderUtils.startsWith(stringBuilder, "23456")); + } + + @Test + public void contains_SingleCharacter() { + StringBuilder stringBuilder = new StringBuilder("abcdefg123456"); + + // This character is not in the string + Assert.assertFalse(StringBuilderUtils.contains(stringBuilder, "z")); + + // All these characters are in the string + for (int n = 0; n < stringBuilder.length(); n++) { + Assert.assertTrue(StringBuilderUtils.contains(stringBuilder, String.valueOf(stringBuilder.charAt(n)))); + } + } + + @Test + public void contains_MultipleCharacters() { + StringBuilder stringBuilder = new StringBuilder("abcdefg123456"); + + // Should return false since characters are in reverse order + Assert.assertFalse(StringBuilderUtils.contains(stringBuilder, "cba")); + + // Should return false since characters are not in string + Assert.assertFalse(StringBuilderUtils.contains(stringBuilder, "zyx")); + } + + @Test + public void equals_SameCharacters() { + StringBuilder stringBuilder = new StringBuilder("abcdefg"); + + Assert.assertTrue(StringBuilderUtils.equals(stringBuilder, "abcdefg")); + } + + @Test + public void equals_DifferentCharacters() { + StringBuilder stringBuilder = new StringBuilder("abcdefg"); + + Assert.assertFalse(StringBuilderUtils.equals(stringBuilder, "abcdefg1")); + } + + @Test + public void substring() { + StringBuilder stringBuilder = new StringBuilder("abcdefg"); + + String string = "abcdefg"; + + Assert.assertEquals(StringBuilderUtils.substring(stringBuilder, 1, 5).toString(), string.substring(1, 5)); + } + +} \ No newline at end of file From 0919c2596933739fb0a7955f7c751d6d74e6b905 Mon Sep 17 00:00:00 2001 From: Zoraver Kang Date: Sun, 18 Jun 2017 10:46:52 -0400 Subject: [PATCH 36/56] Enhanced keyboard shortcuts. Added Ctrl+f to find in page, Alt+ to switch to a specific tab, and Ctrl+Shift+p to open a new private window. Ctrl+p was left reserved for printing. --- .../lightning/activity/BrowserActivity.java | 96 +++++++++++-------- .../lightning/activity/MainActivity.java | 18 ++++ 2 files changed, 75 insertions(+), 39 deletions(-) diff --git a/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java b/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java index 625f0e9..2a8b2a8 100644 --- a/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java +++ b/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java @@ -750,52 +750,70 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @Override public boolean dispatchKeyEvent(KeyEvent event) { // Keyboard shortcuts - if (event.isCtrlPressed() && event.getAction() == KeyEvent.ACTION_DOWN) { - switch (event.getKeyCode()) { - case KeyEvent.KEYCODE_T: - // Open new tab - newTab(null, true); - return true; - case KeyEvent.KEYCODE_W: - // Close current tab - mPresenter.deleteTab(mTabsManager.indexOfCurrentTab()); - return true; - case KeyEvent.KEYCODE_Q: - // Close browser - closeBrowser(); - return true; - case KeyEvent.KEYCODE_R: - // Refresh current tab - LightningView currentTab = mTabsManager.getCurrentTab(); - if (currentTab != null) { - currentTab.reload(); - } - return true; - case KeyEvent.KEYCODE_TAB: - int nextIndex = 0; - if (event.isShiftPressed()) { - // Go back one tab - if (mTabsManager.indexOfCurrentTab() > 0) { - nextIndex = mTabsManager.indexOfCurrentTab() - 1; - } else { - nextIndex = mTabsManager.last(); + if (event.getAction() == KeyEvent.ACTION_DOWN) { + if (event.isCtrlPressed()) { + switch (event.getKeyCode()) { + case KeyEvent.KEYCODE_F: + // Search in page + findInPage(); + return true; + case KeyEvent.KEYCODE_T: + // Open new tab + newTab(null, true); + return true; + case KeyEvent.KEYCODE_W: + // Close current tab + mPresenter.deleteTab(mTabsManager.indexOfCurrentTab()); + return true; + case KeyEvent.KEYCODE_Q: + // Close browser + closeBrowser(); + return true; + case KeyEvent.KEYCODE_R: + // Refresh current tab + LightningView currentTab = mTabsManager.getCurrentTab(); + if (currentTab != null) { + currentTab.reload(); } - } else { - // Go forward one tab - if (mTabsManager.indexOfCurrentTab() < mTabsManager.last()) { - nextIndex = mTabsManager.indexOfCurrentTab() + 1; + return true; + case KeyEvent.KEYCODE_TAB: + int nextIndex = 0; + if (event.isShiftPressed()) { + // Go back one tab + if (mTabsManager.indexOfCurrentTab() > 0) { + nextIndex = mTabsManager.indexOfCurrentTab() - 1; + } else { + nextIndex = mTabsManager.last(); + } } else { - nextIndex = 0; + // Go forward one tab + if (mTabsManager.indexOfCurrentTab() < mTabsManager.last()) { + nextIndex = mTabsManager.indexOfCurrentTab() + 1; + } else { + nextIndex = 0; + } } + mPresenter.tabChanged(nextIndex); + return true; + } + } else if (event.getKeyCode() == KeyEvent.KEYCODE_SEARCH) { + // Highlight search field + mSearch.requestFocus(); + mSearch.selectAll(); + return true; + } else if (event.isAltPressed()) { + // Alt + tab number + if (KeyEvent.KEYCODE_0 <= event.getKeyCode() && event.getKeyCode() <= KeyEvent.KEYCODE_9) { + int nextIndex; + if (event.getKeyCode() > mTabsManager.last() + KeyEvent.KEYCODE_1 || event.getKeyCode() == KeyEvent.KEYCODE_0) { + nextIndex = mTabsManager.last(); + } else { + nextIndex = event.getKeyCode() - KeyEvent.KEYCODE_1; } mPresenter.tabChanged(nextIndex); return true; + } } - } else if (event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_SEARCH) { - // Highlight search field - mSearch.requestFocus(); - mSearch.selectAll(); - return true; } return super.dispatchKeyEvent(event); } diff --git a/app/src/main/java/acr/browser/lightning/activity/MainActivity.java b/app/src/main/java/acr/browser/lightning/activity/MainActivity.java index 0580859..30782b0 100644 --- a/app/src/main/java/acr/browser/lightning/activity/MainActivity.java +++ b/app/src/main/java/acr/browser/lightning/activity/MainActivity.java @@ -4,6 +4,7 @@ import android.content.Intent; import android.os.Build; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.view.KeyEvent; import android.view.Menu; import android.webkit.CookieManager; import android.webkit.CookieSyncManager; @@ -76,5 +77,22 @@ public class MainActivity extends BrowserActivity { }); } + @Override + public boolean dispatchKeyEvent(KeyEvent event) { + if (event.getAction() == KeyEvent.ACTION_DOWN && event.isCtrlPressed()) { + switch (event.getKeyCode()) { + case KeyEvent.KEYCODE_P: + // Open a new private window + if(event.isShiftPressed()) { + startActivity(new Intent(this, IncognitoActivity.class)); + overridePendingTransition(R.anim.slide_up_in, R.anim.fade_out_scale); + return true; + } + break; + } + } + return super.dispatchKeyEvent(event); + } + } From d62cea49e9f999fd1c2d08be87aa643cdb2f54da Mon Sep 17 00:00:00 2001 From: anthony restaino Date: Sun, 18 Jun 2017 11:08:51 -0400 Subject: [PATCH 37/56] Breaking out search box display logic into a ui model --- .../lightning/activity/BrowserActivity.java | 37 +++------- .../browser/lightning/app/AppComponent.java | 4 +- .../lightning/browser/BrowserPresenter.java | 2 +- .../lightning/browser/BrowserView.java | 5 +- .../lightning/browser/SearchBoxModel.java | 71 +++++++++++++++++++ .../lightning/controller/UIController.java | 2 +- .../lightning/view/LightningWebClient.java | 4 +- 7 files changed, 90 insertions(+), 35 deletions(-) create mode 100644 app/src/main/java/acr/browser/lightning/browser/SearchBoxModel.java diff --git a/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java b/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java index 625f0e9..34a4161 100644 --- a/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java +++ b/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java @@ -95,6 +95,7 @@ import acr.browser.lightning.app.BrowserApp; import acr.browser.lightning.browser.BookmarksView; import acr.browser.lightning.browser.BrowserPresenter; import acr.browser.lightning.browser.BrowserView; +import acr.browser.lightning.browser.SearchBoxModel; import acr.browser.lightning.browser.TabsView; import acr.browser.lightning.constant.Constants; import acr.browser.lightning.constant.DownloadsPage; @@ -189,6 +190,8 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @Inject LightningDialogBuilder mBookmarksDialogBuilder; + @Inject SearchBoxModel mSearchBoxModel; + private TabsManager mTabsManager; // Image @@ -510,7 +513,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements final LightningView currentView = mTabsManager.getCurrentTab(); if (!hasFocus && currentView != null) { setIsLoading(currentView.getProgress() < 100); - updateUrl(currentView.getUrl(), true); + updateUrl(currentView.getUrl(), false); } else if (hasFocus && currentView != null) { // Hack to make sure the text gets selected @@ -1112,7 +1115,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements } @Override - public void showBlockedLocalFileDialog(DialogInterface.OnClickListener listener) { + public void showBlockedLocalFileDialog(@NonNull DialogInterface.OnClickListener listener) { AlertDialog.Builder builder = new AlertDialog.Builder(this); Dialog dialog = builder.setCancelable(true) .setTitle(R.string.title_warning) @@ -1534,36 +1537,16 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements } @Override - public void updateUrl(@Nullable String url, boolean shortUrl) { + public void updateUrl(@Nullable String url, boolean isLoading) { if (url == null || mSearch == null || mSearch.hasFocus()) { return; } final LightningView currentTab = mTabsManager.getCurrentTab(); mBookmarksView.handleUpdatedUrl(url); - if (shortUrl && !UrlUtils.isSpecialUrl(url)) { - switch (mPreferences.getUrlBoxContentChoice()) { - case 0: // Default, show only the domain - url = url.replaceFirst(Constants.HTTP, ""); - url = Utils.getDomainName(url); - mSearch.setText(url); - break; - case 1: // URL, show the entire URL - mSearch.setText(url); - break; - case 2: // Title, show the page's title - if (currentTab != null && !currentTab.getTitle().isEmpty()) { - mSearch.setText(currentTab.getTitle()); - } else { - mSearch.setText(mUntitledTitle); - } - break; - } - } else { - if (UrlUtils.isSpecialUrl(url)) { - url = ""; - } - mSearch.setText(url); - } + + String currentTitle = currentTab != null ? currentTab.getTitle() : null; + + mSearch.setText(mSearchBoxModel.getDisplayContent(url, currentTitle, isLoading)); } @Override diff --git a/app/src/main/java/acr/browser/lightning/app/AppComponent.java b/app/src/main/java/acr/browser/lightning/app/AppComponent.java index c47e3f4..4b74766 100644 --- a/app/src/main/java/acr/browser/lightning/app/AppComponent.java +++ b/app/src/main/java/acr/browser/lightning/app/AppComponent.java @@ -8,11 +8,11 @@ import acr.browser.lightning.activity.TabsManager; import acr.browser.lightning.activity.ThemableBrowserActivity; import acr.browser.lightning.activity.ThemableSettingsActivity; import acr.browser.lightning.browser.BrowserPresenter; +import acr.browser.lightning.browser.SearchBoxModel; import acr.browser.lightning.constant.BookmarkPage; import acr.browser.lightning.constant.DownloadsPage; import acr.browser.lightning.constant.HistoryPage; import acr.browser.lightning.constant.StartPage; -import acr.browser.lightning.database.history.HistoryDatabase; import acr.browser.lightning.dialog.LightningDialogBuilder; import acr.browser.lightning.download.DownloadHandler; import acr.browser.lightning.download.LightningDownloadListener; @@ -83,6 +83,6 @@ public interface AppComponent { void inject(DownloadHandler downloadHandler); - HistoryDatabase historyDatabase(); + void inject(SearchBoxModel searchBoxModel); } diff --git a/app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java b/app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java index 691d742..c53258c 100644 --- a/app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java +++ b/app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java @@ -121,7 +121,7 @@ public class BrowserPresenter { mView.updateProgress(newTab.getProgress()); mView.setBackButtonEnabled(newTab.canGoBack()); mView.setForwardButtonEnabled(newTab.canGoForward()); - mView.updateUrl(newTab.getUrl(), true); + mView.updateUrl(newTab.getUrl(), false); mView.setTabView(newTab.getWebView()); int index = mTabsModel.indexOfTab(newTab); if (index >= 0) { diff --git a/app/src/main/java/acr/browser/lightning/browser/BrowserView.java b/app/src/main/java/acr/browser/lightning/browser/BrowserView.java index b701bbb..e301a0c 100644 --- a/app/src/main/java/acr/browser/lightning/browser/BrowserView.java +++ b/app/src/main/java/acr/browser/lightning/browser/BrowserView.java @@ -2,6 +2,7 @@ package acr.browser.lightning.browser; import android.content.DialogInterface; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.support.annotation.StringRes; import android.view.View; @@ -11,7 +12,7 @@ public interface BrowserView { void removeTabView(); - void updateUrl(String url, boolean shortUrl); + void updateUrl(@Nullable String url, boolean isLoading); void updateProgress(int progress); @@ -21,7 +22,7 @@ public interface BrowserView { void closeActivity(); - void showBlockedLocalFileDialog(DialogInterface.OnClickListener listener); + void showBlockedLocalFileDialog(@NonNull DialogInterface.OnClickListener listener); void showSnackbar(@StringRes int resource); diff --git a/app/src/main/java/acr/browser/lightning/browser/SearchBoxModel.java b/app/src/main/java/acr/browser/lightning/browser/SearchBoxModel.java new file mode 100644 index 0000000..c426677 --- /dev/null +++ b/app/src/main/java/acr/browser/lightning/browser/SearchBoxModel.java @@ -0,0 +1,71 @@ +package acr.browser.lightning.browser; + +import android.app.Application; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.text.TextUtils; + +import javax.inject.Inject; + +import acr.browser.lightning.R; +import acr.browser.lightning.app.BrowserApp; +import acr.browser.lightning.preference.PreferenceManager; +import acr.browser.lightning.utils.UrlUtils; +import acr.browser.lightning.utils.Utils; + +/** + * A UI model for the search box. + */ +public class SearchBoxModel { + + @Inject PreferenceManager mPreferences; + @Inject Application mApplication; + + @NonNull private final String mUntitledTitle; + + @Inject + public SearchBoxModel() { + BrowserApp.getAppComponent().inject(this); + mUntitledTitle = mApplication.getString(R.string.untitled); + } + + /** + * Returns the contents of the search box based on a variety of factors. + *
  • + *
      The user's preference to show either the URL, domain, or page title
    + *
      Whether or not the current page is loading
    + *
      Whether or not the current page is a Lightning generated page.
    + *
  • + * This method uses the URL, title, and loading information to determine what + * should be displayed by the search box. + * + * @param url the URL of the current page. + * @param title the title of the current page, if known. + * @param isLoading whether the page is currently loading or not. + * @return the string that should be displayed by the search box. + */ + @NonNull + public String getDisplayContent(@NonNull String url, @Nullable String title, boolean isLoading) { + if (UrlUtils.isSpecialUrl(url)) { + return ""; + } else if (isLoading) { + return url; + } else { + switch (mPreferences.getUrlBoxContentChoice()) { + default: + case 0: // Default, show only the domain + String domain = Utils.getDomainName(url); + return domain != null ? domain : url; + case 1: // URL, show the entire URL + return url; + case 2: // Title, show the page's title + if (!TextUtils.isEmpty(title)) { + return title; + } else { + return mUntitledTitle; + } + } + } + } + +} diff --git a/app/src/main/java/acr/browser/lightning/controller/UIController.java b/app/src/main/java/acr/browser/lightning/controller/UIController.java index a9021a7..c708585 100644 --- a/app/src/main/java/acr/browser/lightning/controller/UIController.java +++ b/app/src/main/java/acr/browser/lightning/controller/UIController.java @@ -28,7 +28,7 @@ public interface UIController { boolean getUseDarkTheme(); - void updateUrl(@Nullable String title, boolean shortUrl); + void updateUrl(@Nullable String title, boolean isLoading); void updateProgress(int n); diff --git a/app/src/main/java/acr/browser/lightning/view/LightningWebClient.java b/app/src/main/java/acr/browser/lightning/view/LightningWebClient.java index ae959bd..5378019 100644 --- a/app/src/main/java/acr/browser/lightning/view/LightningWebClient.java +++ b/app/src/main/java/acr/browser/lightning/view/LightningWebClient.java @@ -102,7 +102,7 @@ public class LightningWebClient extends WebViewClient { @Override public void onPageFinished(@NonNull WebView view, String url) { if (view.isShown()) { - mUIController.updateUrl(url, true); + mUIController.updateUrl(url, false); mUIController.setBackButtonEnabled(view.canGoBack()); mUIController.setForwardButtonEnabled(view.canGoForward()); view.postInvalidate(); @@ -123,7 +123,7 @@ public class LightningWebClient extends WebViewClient { public void onPageStarted(WebView view, String url, Bitmap favicon) { mLightningView.getTitleInfo().setFavicon(null); if (mLightningView.isShown()) { - mUIController.updateUrl(url, false); + mUIController.updateUrl(url, true); mUIController.showActionBar(); } mUIController.tabChanged(mLightningView); From e8e73ae488a89710b31f801011cc1f623b8617fc Mon Sep 17 00:00:00 2001 From: anthony restaino Date: Sun, 18 Jun 2017 11:51:14 -0400 Subject: [PATCH 38/56] Improving the way search engines are handled --- .../lightning/activity/BrowserActivity.java | 45 +------ .../browser/lightning/app/AppComponent.java | 3 + .../browser/lightning/constant/StartPage.java | 124 ++++-------------- .../search/SearchEngineProvider.java | 64 +++++++++ .../lightning/search/engine/AskSearch.java | 14 ++ .../lightning/search/engine/BaiduSearch.java | 16 +++ .../search/engine/BaseSearchEngine.java | 33 +++++ .../lightning/search/engine/BingSearch.java | 18 +++ .../lightning/search/engine/CustomSearch.java | 14 ++ .../search/engine/DuckLiteSearch.java | 16 +++ .../lightning/search/engine/DuckSearch.java | 16 +++ .../lightning/search/engine/GoogleSearch.java | 15 +++ .../search/engine/StartPageMobileSearch.java | 14 ++ .../search/engine/StartPageSearch.java | 14 ++ .../lightning/search/engine/YahooSearch.java | 17 +++ .../lightning/search/engine/YandexSearch.java | 17 +++ 16 files changed, 305 insertions(+), 135 deletions(-) create mode 100644 app/src/main/java/acr/browser/lightning/search/SearchEngineProvider.java create mode 100644 app/src/main/java/acr/browser/lightning/search/engine/AskSearch.java create mode 100644 app/src/main/java/acr/browser/lightning/search/engine/BaiduSearch.java create mode 100644 app/src/main/java/acr/browser/lightning/search/engine/BaseSearchEngine.java create mode 100644 app/src/main/java/acr/browser/lightning/search/engine/BingSearch.java create mode 100644 app/src/main/java/acr/browser/lightning/search/engine/CustomSearch.java create mode 100644 app/src/main/java/acr/browser/lightning/search/engine/DuckLiteSearch.java create mode 100644 app/src/main/java/acr/browser/lightning/search/engine/DuckSearch.java create mode 100644 app/src/main/java/acr/browser/lightning/search/engine/GoogleSearch.java create mode 100644 app/src/main/java/acr/browser/lightning/search/engine/StartPageMobileSearch.java create mode 100644 app/src/main/java/acr/browser/lightning/search/engine/StartPageSearch.java create mode 100644 app/src/main/java/acr/browser/lightning/search/engine/YahooSearch.java create mode 100644 app/src/main/java/acr/browser/lightning/search/engine/YandexSearch.java diff --git a/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java b/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java index 34a4161..2756320 100644 --- a/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java +++ b/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java @@ -61,7 +61,6 @@ import android.view.animation.Animation; import android.view.animation.Transformation; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputMethodManager; -import android.webkit.URLUtil; import android.webkit.ValueCallback; import android.webkit.WebChromeClient.CustomViewCallback; import android.webkit.WebIconDatabase; @@ -110,7 +109,9 @@ import acr.browser.lightning.fragment.BookmarksFragment; import acr.browser.lightning.fragment.TabsFragment; import acr.browser.lightning.interpolator.BezierDecelerateInterpolator; import acr.browser.lightning.receiver.NetworkReceiver; +import acr.browser.lightning.search.SearchEngineProvider; import acr.browser.lightning.search.SuggestionsAdapter; +import acr.browser.lightning.search.engine.BaseSearchEngine; import acr.browser.lightning.utils.DrawableUtils; import acr.browser.lightning.utils.IntentUtils; import acr.browser.lightning.utils.Preconditions; @@ -192,6 +193,8 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @Inject SearchBoxModel mSearchBoxModel; + @Inject SearchEngineProvider mSearchEngineProvider; + private TabsManager mTabsManager; // Image @@ -657,44 +660,8 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements setFullscreen(mPreferences.getHideStatusBarEnabled(), false); - switch (mPreferences.getSearchChoice()) { - case 0: - mSearchText = mPreferences.getSearchUrl(); - if (!URLUtil.isNetworkUrl(mSearchText)) { - mSearchText = Constants.GOOGLE_SEARCH; - } - break; - case 1: - mSearchText = Constants.GOOGLE_SEARCH; - break; - case 2: - mSearchText = Constants.ASK_SEARCH; - break; - case 3: - mSearchText = Constants.BING_SEARCH; - break; - case 4: - mSearchText = Constants.YAHOO_SEARCH; - break; - case 5: - mSearchText = Constants.STARTPAGE_SEARCH; - break; - case 6: - mSearchText = Constants.STARTPAGE_MOBILE_SEARCH; - break; - case 7: - mSearchText = Constants.DUCK_SEARCH; - break; - case 8: - mSearchText = Constants.DUCK_LITE_SEARCH; - break; - case 9: - mSearchText = Constants.BAIDU_SEARCH; - break; - case 10: - mSearchText = Constants.YANDEX_SEARCH; - break; - } + BaseSearchEngine currentSearchEngine = mSearchEngineProvider.getCurrentSearchEngine(); + mSearchText = currentSearchEngine.getQueryUrl(); updateCookiePreference().subscribeOn(Schedulers.worker()).subscribe(); mProxyUtils.updateProxySettings(this); diff --git a/app/src/main/java/acr/browser/lightning/app/AppComponent.java b/app/src/main/java/acr/browser/lightning/app/AppComponent.java index 4b74766..3683d5f 100644 --- a/app/src/main/java/acr/browser/lightning/app/AppComponent.java +++ b/app/src/main/java/acr/browser/lightning/app/AppComponent.java @@ -22,6 +22,7 @@ import acr.browser.lightning.fragment.DebugSettingsFragment; import acr.browser.lightning.fragment.LightningPreferenceFragment; import acr.browser.lightning.fragment.PrivacySettingsFragment; import acr.browser.lightning.fragment.TabsFragment; +import acr.browser.lightning.search.SearchEngineProvider; import acr.browser.lightning.search.SuggestionsAdapter; import acr.browser.lightning.utils.ProxyUtils; import acr.browser.lightning.view.LightningChromeClient; @@ -85,4 +86,6 @@ public interface AppComponent { void inject(SearchBoxModel searchBoxModel); + void inject(SearchEngineProvider searchEngineProvider); + } diff --git a/app/src/main/java/acr/browser/lightning/constant/StartPage.java b/app/src/main/java/acr/browser/lightning/constant/StartPage.java index 5bb1a63..873481e 100644 --- a/app/src/main/java/acr/browser/lightning/constant/StartPage.java +++ b/app/src/main/java/acr/browser/lightning/constant/StartPage.java @@ -18,7 +18,8 @@ import javax.inject.Inject; import acr.browser.lightning.R; import acr.browser.lightning.app.BrowserApp; -import acr.browser.lightning.preference.PreferenceManager; +import acr.browser.lightning.search.SearchEngineProvider; +import acr.browser.lightning.search.engine.BaseSearchEngine; import acr.browser.lightning.utils.Utils; public class StartPage { @@ -26,31 +27,31 @@ public class StartPage { public static final String FILENAME = "homepage.html"; private static final String HEAD_1 = "" - + "" - + "" - + "" - + "" - + ""; + + "<head>" + + "<meta content=\"en-us\" http-equiv=\"Content-Language\" />" + + "<meta content=\"text/html; charset=utf-8\" http-equiv=\"Content-Type\" />" + + "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no\">" + + "<title>"; private static final String HEAD_2 = "" - + "" - + "
    " + + "


    " - + "" - + "


    "; @@ -62,7 +63,7 @@ public class StartPage { @NonNull private final String mTitle; @Inject Application mApp; - @Inject PreferenceManager mPreferenceManager; + @Inject SearchEngineProvider mSearchEngineProvider; public StartPage() { BrowserApp.getAppComponent().inject(this); @@ -76,80 +77,11 @@ public class StartPage { public void onSubscribe(@NonNull SingleSubscriber subscriber) { StringBuilder homepageBuilder = new StringBuilder(HEAD_1 + mTitle + HEAD_2); - String icon; - String searchUrl; - switch (mPreferenceManager.getSearchChoice()) { - case 0: - // CUSTOM SEARCH - icon = "file:///android_asset/lightning.png"; - searchUrl = mPreferenceManager.getSearchUrl(); - break; - case 1: - // GOOGLE_SEARCH; - icon = "file:///android_asset/google.png"; - // "https://www.google.com/images/srpr/logo11w.png"; - searchUrl = Constants.GOOGLE_SEARCH; - break; - case 2: - // ANDROID SEARCH; - icon = "file:///android_asset/ask.png"; - searchUrl = Constants.ASK_SEARCH; - break; - case 3: - // BING_SEARCH; - icon = "file:///android_asset/bing.png"; - // "http://upload.wikimedia.org/wikipedia/commons/thumb/b/b1/Bing_logo_%282013%29.svg/500px-Bing_logo_%282013%29.svg.png"; - searchUrl = Constants.BING_SEARCH; - break; - case 4: - // YAHOO_SEARCH; - icon = "file:///android_asset/yahoo.png"; - // "http://upload.wikimedia.org/wikipedia/commons/thumb/2/24/Yahoo%21_logo.svg/799px-Yahoo%21_logo.svg.png"; - searchUrl = Constants.YAHOO_SEARCH; - break; - case 5: - // STARTPAGE_SEARCH; - icon = "file:///android_asset/startpage.png"; - // "https://com/graphics/startp_logo.gif"; - searchUrl = Constants.STARTPAGE_SEARCH; - break; - case 6: - // STARTPAGE_MOBILE - icon = "file:///android_asset/startpage.png"; - // "https://com/graphics/startp_logo.gif"; - searchUrl = Constants.STARTPAGE_MOBILE_SEARCH; - break; - case 7: - // DUCK_SEARCH; - icon = "file:///android_asset/duckduckgo.png"; - // "https://duckduckgo.com/assets/logo_homepage.normal.v101.png"; - searchUrl = Constants.DUCK_SEARCH; - break; - case 8: - // DUCK_LITE_SEARCH; - icon = "file:///android_asset/duckduckgo.png"; - // "https://duckduckgo.com/assets/logo_homepage.normal.v101.png"; - searchUrl = Constants.DUCK_LITE_SEARCH; - break; - case 9: - // BAIDU_SEARCH; - icon = "file:///android_asset/baidu.png"; - // "http://www.baidu.com/img/bdlogo.gif"; - searchUrl = Constants.BAIDU_SEARCH; - break; - case 10: - // YANDEX_SEARCH; - icon = "file:///android_asset/yandex.png"; - // "http://upload.wikimedia.org/wikipedia/commons/thumb/9/91/Yandex.svg/600px-Yandex.svg.png"; - searchUrl = Constants.YANDEX_SEARCH; - break; - default: - // DEFAULT GOOGLE_SEARCH; - icon = "file:///android_asset/google.png"; - searchUrl = Constants.GOOGLE_SEARCH; - break; - } + BaseSearchEngine currentSearchEngine = mSearchEngineProvider.getCurrentSearchEngine(); + + String icon = currentSearchEngine.getIconUrl(); + String searchUrl = currentSearchEngine.getQueryUrl(); homepageBuilder.append(icon); homepageBuilder.append(MIDDLE); diff --git a/app/src/main/java/acr/browser/lightning/search/SearchEngineProvider.java b/app/src/main/java/acr/browser/lightning/search/SearchEngineProvider.java new file mode 100644 index 0000000..1e27a9f --- /dev/null +++ b/app/src/main/java/acr/browser/lightning/search/SearchEngineProvider.java @@ -0,0 +1,64 @@ +package acr.browser.lightning.search; + +import android.support.annotation.NonNull; + +import javax.inject.Inject; + +import acr.browser.lightning.app.BrowserApp; +import acr.browser.lightning.preference.PreferenceManager; +import acr.browser.lightning.search.engine.AskSearch; +import acr.browser.lightning.search.engine.BaiduSearch; +import acr.browser.lightning.search.engine.BaseSearchEngine; +import acr.browser.lightning.search.engine.BingSearch; +import acr.browser.lightning.search.engine.CustomSearch; +import acr.browser.lightning.search.engine.DuckLiteSearch; +import acr.browser.lightning.search.engine.DuckSearch; +import acr.browser.lightning.search.engine.GoogleSearch; +import acr.browser.lightning.search.engine.StartPageMobileSearch; +import acr.browser.lightning.search.engine.StartPageSearch; +import acr.browser.lightning.search.engine.YahooSearch; +import acr.browser.lightning.search.engine.YandexSearch; + +/** + * The model that provides the search engine based + * on the user's preference. + */ +public class SearchEngineProvider { + + @Inject PreferenceManager mPreferenceManager; + + @Inject + public SearchEngineProvider() { + BrowserApp.getAppComponent().inject(this); + } + + @NonNull + public BaseSearchEngine getCurrentSearchEngine() { + switch (mPreferenceManager.getSearchChoice()) { + case 0: + return new CustomSearch(mPreferenceManager.getSearchUrl()); + case 1: + default: + return new GoogleSearch(); + case 2: + return new AskSearch(); + case 3: + return new BingSearch(); + case 4: + return new YahooSearch(); + case 5: + return new StartPageSearch(); + case 6: + return new StartPageMobileSearch(); + case 7: + return new DuckSearch(); + case 8: + return new DuckLiteSearch(); + case 9: + return new BaiduSearch(); + case 10: + return new YandexSearch(); + } + } + +} diff --git a/app/src/main/java/acr/browser/lightning/search/engine/AskSearch.java b/app/src/main/java/acr/browser/lightning/search/engine/AskSearch.java new file mode 100644 index 0000000..27aa160 --- /dev/null +++ b/app/src/main/java/acr/browser/lightning/search/engine/AskSearch.java @@ -0,0 +1,14 @@ +package acr.browser.lightning.search.engine; + +import acr.browser.lightning.constant.Constants; + +/** + * The Ask search engine. + */ +public class AskSearch extends BaseSearchEngine { + + public AskSearch() { + super("file:///android_asset/ask.png", Constants.ASK_SEARCH); + } + +} diff --git a/app/src/main/java/acr/browser/lightning/search/engine/BaiduSearch.java b/app/src/main/java/acr/browser/lightning/search/engine/BaiduSearch.java new file mode 100644 index 0000000..bc46e7d --- /dev/null +++ b/app/src/main/java/acr/browser/lightning/search/engine/BaiduSearch.java @@ -0,0 +1,16 @@ +package acr.browser.lightning.search.engine; + +import acr.browser.lightning.constant.Constants; + +/** + * The Baidu search engine. + *

    + * See http://www.baidu.com/img/bdlogo.gif for the icon. + */ +public class BaiduSearch extends BaseSearchEngine { + + public BaiduSearch() { + super("file:///android_asset/baidu.png", Constants.BAIDU_SEARCH); + } + +} diff --git a/app/src/main/java/acr/browser/lightning/search/engine/BaseSearchEngine.java b/app/src/main/java/acr/browser/lightning/search/engine/BaseSearchEngine.java new file mode 100644 index 0000000..009d22a --- /dev/null +++ b/app/src/main/java/acr/browser/lightning/search/engine/BaseSearchEngine.java @@ -0,0 +1,33 @@ +package acr.browser.lightning.search.engine; + +import android.support.annotation.NonNull; + +import acr.browser.lightning.utils.Preconditions; + +/** + * A class representative of a search engine. + */ +public class BaseSearchEngine { + + @NonNull private final String mIconUrl; + @NonNull private final String mQueryUrl; + + public BaseSearchEngine(@NonNull String iconUrl, @NonNull String queryUrl) { + Preconditions.checkNonNull(iconUrl); + Preconditions.checkNonNull(queryUrl); + + mIconUrl = iconUrl; + mQueryUrl = queryUrl; + } + + @NonNull + public final String getIconUrl() { + return mIconUrl; + } + + @NonNull + public final String getQueryUrl() { + return mQueryUrl; + } + +} diff --git a/app/src/main/java/acr/browser/lightning/search/engine/BingSearch.java b/app/src/main/java/acr/browser/lightning/search/engine/BingSearch.java new file mode 100644 index 0000000..c3e95dc --- /dev/null +++ b/app/src/main/java/acr/browser/lightning/search/engine/BingSearch.java @@ -0,0 +1,18 @@ +package acr.browser.lightning.search.engine; + +import acr.browser.lightning.constant.Constants; + +/** + * The Bing search engine. + *

    + * See http://upload.wikimedia.org/wikipedia/commons/thumb/b/b1/Bing_logo_%282013%29.svg/500px-Bing_logo_%282013%29.svg.png + * for the icon. + */ +public class BingSearch extends BaseSearchEngine { + + public BingSearch() { + super("file:///android_asset/bing.png", Constants.BING_SEARCH); + // "http://upload.wikimedia.org/wikipedia/commons/thumb/b/b1/Bing_logo_%282013%29.svg/500px-Bing_logo_%282013%29.svg.png"; + } + +} diff --git a/app/src/main/java/acr/browser/lightning/search/engine/CustomSearch.java b/app/src/main/java/acr/browser/lightning/search/engine/CustomSearch.java new file mode 100644 index 0000000..fb7a170 --- /dev/null +++ b/app/src/main/java/acr/browser/lightning/search/engine/CustomSearch.java @@ -0,0 +1,14 @@ +package acr.browser.lightning.search.engine; + +import android.support.annotation.NonNull; + +/** + * A custom search engine. + */ +public class CustomSearch extends BaseSearchEngine { + + public CustomSearch(@NonNull String queryUrl) { + super("file:///android_asset/lightning.png", queryUrl); + } + +} diff --git a/app/src/main/java/acr/browser/lightning/search/engine/DuckLiteSearch.java b/app/src/main/java/acr/browser/lightning/search/engine/DuckLiteSearch.java new file mode 100644 index 0000000..81c2b31 --- /dev/null +++ b/app/src/main/java/acr/browser/lightning/search/engine/DuckLiteSearch.java @@ -0,0 +1,16 @@ +package acr.browser.lightning.search.engine; + +import acr.browser.lightning.constant.Constants; + +/** + * The DuckDuckGo Lite search engine. + *

    + * See https://duckduckgo.com/assets/logo_homepage.normal.v101.png for the icon. + */ +public class DuckLiteSearch extends BaseSearchEngine { + + public DuckLiteSearch() { + super("file:///android_asset/duckduckgo.png", Constants.DUCK_LITE_SEARCH); + } + +} diff --git a/app/src/main/java/acr/browser/lightning/search/engine/DuckSearch.java b/app/src/main/java/acr/browser/lightning/search/engine/DuckSearch.java new file mode 100644 index 0000000..cf9d85d --- /dev/null +++ b/app/src/main/java/acr/browser/lightning/search/engine/DuckSearch.java @@ -0,0 +1,16 @@ +package acr.browser.lightning.search.engine; + +import acr.browser.lightning.constant.Constants; + +/** + * The DuckDuckGo search engine. + *

    + * See https://duckduckgo.com/assets/logo_homepage.normal.v101.png for the icon. + */ +public class DuckSearch extends BaseSearchEngine { + + public DuckSearch() { + super("file:///android_asset/duckduckgo.png", Constants.DUCK_SEARCH); + } + +} diff --git a/app/src/main/java/acr/browser/lightning/search/engine/GoogleSearch.java b/app/src/main/java/acr/browser/lightning/search/engine/GoogleSearch.java new file mode 100644 index 0000000..ef08792 --- /dev/null +++ b/app/src/main/java/acr/browser/lightning/search/engine/GoogleSearch.java @@ -0,0 +1,15 @@ +package acr.browser.lightning.search.engine; + +import acr.browser.lightning.constant.Constants; + +/** + * The Google search engine. + *

    + * See https://www.google.com/images/srpr/logo11w.png for the icon. + */ +public class GoogleSearch extends BaseSearchEngine { + + public GoogleSearch() { + super("file:///android_asset/google.png", Constants.GOOGLE_SEARCH); + } +} diff --git a/app/src/main/java/acr/browser/lightning/search/engine/StartPageMobileSearch.java b/app/src/main/java/acr/browser/lightning/search/engine/StartPageMobileSearch.java new file mode 100644 index 0000000..e150874 --- /dev/null +++ b/app/src/main/java/acr/browser/lightning/search/engine/StartPageMobileSearch.java @@ -0,0 +1,14 @@ +package acr.browser.lightning.search.engine; + +import acr.browser.lightning.constant.Constants; + +/** + * The StartPage mobile search engine. + */ +public class StartPageMobileSearch extends BaseSearchEngine { + + public StartPageMobileSearch() { + super("file:///android_asset/startpage.png", Constants.STARTPAGE_MOBILE_SEARCH); + } + +} diff --git a/app/src/main/java/acr/browser/lightning/search/engine/StartPageSearch.java b/app/src/main/java/acr/browser/lightning/search/engine/StartPageSearch.java new file mode 100644 index 0000000..ef84bc1 --- /dev/null +++ b/app/src/main/java/acr/browser/lightning/search/engine/StartPageSearch.java @@ -0,0 +1,14 @@ +package acr.browser.lightning.search.engine; + +import acr.browser.lightning.constant.Constants; + +/** + * The StartPage search engine. + */ +public class StartPageSearch extends BaseSearchEngine { + + public StartPageSearch() { + super("file:///android_asset/startpage.png", Constants.STARTPAGE_SEARCH); + } + +} diff --git a/app/src/main/java/acr/browser/lightning/search/engine/YahooSearch.java b/app/src/main/java/acr/browser/lightning/search/engine/YahooSearch.java new file mode 100644 index 0000000..8bfec27 --- /dev/null +++ b/app/src/main/java/acr/browser/lightning/search/engine/YahooSearch.java @@ -0,0 +1,17 @@ +package acr.browser.lightning.search.engine; + +import acr.browser.lightning.constant.Constants; + +/** + * The Yahoo search engine. + *

    + * See http://upload.wikimedia.org/wikipedia/commons/thumb/2/24/Yahoo%21_logo.svg/799px-Yahoo%21_logo.svg.png + * for the icon. + */ +public class YahooSearch extends BaseSearchEngine { + + public YahooSearch() { + super("file:///android_asset/yahoo.png", Constants.YAHOO_SEARCH); + } + +} diff --git a/app/src/main/java/acr/browser/lightning/search/engine/YandexSearch.java b/app/src/main/java/acr/browser/lightning/search/engine/YandexSearch.java new file mode 100644 index 0000000..917fd63 --- /dev/null +++ b/app/src/main/java/acr/browser/lightning/search/engine/YandexSearch.java @@ -0,0 +1,17 @@ +package acr.browser.lightning.search.engine; + +import acr.browser.lightning.constant.Constants; + +/** + * The Yandex search engine. + *

    + * See http://upload.wikimedia.org/wikipedia/commons/thumb/9/91/Yandex.svg/600px-Yandex.svg.png + * for the icon. + */ +public class YandexSearch extends BaseSearchEngine { + + public YandexSearch() { + super("file:///android_asset/yandex.png", Constants.YANDEX_SEARCH); + } + +} From 93be0afee4fd4d33d052362ca6a214b87a8fb51a Mon Sep 17 00:00:00 2001 From: anthony restaino Date: Sun, 18 Jun 2017 12:25:40 -0400 Subject: [PATCH 39/56] Fixing javadocs --- .../acr/browser/lightning/browser/SearchBoxModel.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/acr/browser/lightning/browser/SearchBoxModel.java b/app/src/main/java/acr/browser/lightning/browser/SearchBoxModel.java index c426677..8d5a179 100644 --- a/app/src/main/java/acr/browser/lightning/browser/SearchBoxModel.java +++ b/app/src/main/java/acr/browser/lightning/browser/SearchBoxModel.java @@ -31,11 +31,11 @@ public class SearchBoxModel { /** * Returns the contents of the search box based on a variety of factors. - *

  • - *
      The user's preference to show either the URL, domain, or page title
    - *
      Whether or not the current page is loading
    - *
      Whether or not the current page is a Lightning generated page.
    - *
  • + *
      + *
    • The user's preference to show either the URL, domain, or page title
    • + *
    • Whether or not the current page is loading
    • + *
    • Whether or not the current page is a Lightning generated page.
    • + *
    * This method uses the URL, title, and loading information to determine what * should be displayed by the search box. * From cf94963255c9a0f4c42ec87cdf79af5818514545 Mon Sep 17 00:00:00 2001 From: anthony restaino Date: Sun, 18 Jun 2017 12:47:34 -0400 Subject: [PATCH 40/56] Improving the way search engine preferences are handled --- .../browser/lightning/app/AppComponent.java | 3 + .../fragment/GeneralSettingsFragment.java | 96 ++++++++++--------- .../search/SearchEngineProvider.java | 48 ++++++++++ .../lightning/search/engine/AskSearch.java | 3 +- .../lightning/search/engine/BaiduSearch.java | 3 +- .../search/engine/BaseSearchEngine.java | 20 +++- .../lightning/search/engine/BingSearch.java | 4 +- .../lightning/search/engine/CustomSearch.java | 4 +- .../search/engine/DuckLiteSearch.java | 3 +- .../lightning/search/engine/DuckSearch.java | 3 +- .../lightning/search/engine/GoogleSearch.java | 3 +- .../search/engine/StartPageMobileSearch.java | 3 +- .../search/engine/StartPageSearch.java | 3 +- .../lightning/search/engine/YahooSearch.java | 3 +- .../lightning/search/engine/YandexSearch.java | 3 +- app/src/main/res/values-de/strings.xml | 2 +- app/src/main/res/values-el/strings.xml | 2 +- app/src/main/res/values-es/strings.xml | 2 +- app/src/main/res/values-fr/strings.xml | 2 +- app/src/main/res/values-hu/strings.xml | 2 +- app/src/main/res/values-it/strings.xml | 2 +- app/src/main/res/values-ja/strings.xml | 2 +- app/src/main/res/values-ko/strings.xml | 2 +- app/src/main/res/values-nl/strings.xml | 2 +- app/src/main/res/values-pl/strings.xml | 2 +- app/src/main/res/values-pt-rBR/strings.xml | 2 +- app/src/main/res/values-pt/strings.xml | 2 +- app/src/main/res/values-ru/strings.xml | 2 +- app/src/main/res/values-sr/strings.xml | 2 +- app/src/main/res/values-tr/strings.xml | 2 +- app/src/main/res/values-zh-rCN/strings.xml | 2 +- app/src/main/res/values-zh-rTW/strings.xml | 2 +- app/src/main/res/values/strings.xml | 14 ++- 33 files changed, 174 insertions(+), 76 deletions(-) diff --git a/app/src/main/java/acr/browser/lightning/app/AppComponent.java b/app/src/main/java/acr/browser/lightning/app/AppComponent.java index 3683d5f..17f7c12 100644 --- a/app/src/main/java/acr/browser/lightning/app/AppComponent.java +++ b/app/src/main/java/acr/browser/lightning/app/AppComponent.java @@ -19,6 +19,7 @@ import acr.browser.lightning.download.LightningDownloadListener; import acr.browser.lightning.fragment.BookmarkSettingsFragment; import acr.browser.lightning.fragment.BookmarksFragment; import acr.browser.lightning.fragment.DebugSettingsFragment; +import acr.browser.lightning.fragment.GeneralSettingsFragment; import acr.browser.lightning.fragment.LightningPreferenceFragment; import acr.browser.lightning.fragment.PrivacySettingsFragment; import acr.browser.lightning.fragment.TabsFragment; @@ -88,4 +89,6 @@ public interface AppComponent { void inject(SearchEngineProvider searchEngineProvider); + void inject(GeneralSettingsFragment generalSettingsFragment); + } diff --git a/app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java b/app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java index b6627cb..77446c0 100644 --- a/app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java +++ b/app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java @@ -22,10 +22,18 @@ import android.view.View; import android.webkit.URLUtil; import android.widget.EditText; +import java.util.List; + +import javax.inject.Inject; + import acr.browser.lightning.BuildConfig; import acr.browser.lightning.R; +import acr.browser.lightning.app.BrowserApp; import acr.browser.lightning.constant.Constants; import acr.browser.lightning.dialog.BrowserDialog; +import acr.browser.lightning.search.SearchEngineProvider; +import acr.browser.lightning.search.engine.BaseSearchEngine; +import acr.browser.lightning.search.engine.CustomSearch; import acr.browser.lightning.utils.FileUtils; import acr.browser.lightning.utils.ProxyUtils; import acr.browser.lightning.utils.ThemeUtils; @@ -54,12 +62,16 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme private int mAgentChoice; private String mHomepage; + @Inject SearchEngineProvider mSearchEngineProvider; + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Load the preferences from an XML resource addPreferencesFromResource(R.xml.preference_general); + BrowserApp.getAppComponent().inject(this); + mActivity = getActivity(); initPrefs(); @@ -107,7 +119,8 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme mPreferenceManager.setFlashSupport(0); } - setSearchEngineSummary(mPreferenceManager.getSearchChoice()); + BaseSearchEngine currentSearchEngine = mSearchEngineProvider.getCurrentSearchEngine(); + setSearchEngineSummary(currentSearchEngine); downloadloc.setSummary(mDownloadLocation); @@ -175,18 +188,18 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme cbColorMode.setChecked(mPreferenceManager.getColorModeEnabled()); } - private void searchUrlPicker() { + private void showUrlPicker(@NonNull final CustomSearch customSearch) { BrowserDialog.showEditText(mActivity, - R.string.custom_url, - R.string.custom_url, + R.string.search_engine_custom, + R.string.search_engine_custom, mPreferenceManager.getSearchUrl(), R.string.action_ok, new BrowserDialog.EditorListener() { @Override public void onClick(String text) { mPreferenceManager.setSearchUrl(text); - searchengine.setSummary(mActivity.getString(R.string.custom_url) + ": " + text); + setSearchEngineSummary(customSearch); } }); @@ -299,13 +312,24 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme BrowserDialog.setDialogSize(mActivity, dialog); } + @NonNull + private CharSequence[] convertSearchEngineToString(@NonNull List searchEngines) { + CharSequence[] titles = new CharSequence[searchEngines.size()]; + + for (int n = 0; n < searchEngines.size(); n++) { + titles[n] = getString(searchEngines.get(n).getTitleRes()); + } + + return titles; + } + private void searchDialog() { AlertDialog.Builder picker = new AlertDialog.Builder(mActivity); picker.setTitle(getResources().getString(R.string.title_search_engine)); - CharSequence[] chars = {getResources().getString(R.string.custom_url), "Google", - "Ask", "Bing", "Yahoo", "StartPage", "StartPage (Mobile)", - "DuckDuckGo (Privacy)", "DuckDuckGo Lite (Privacy)", "Baidu (Chinese)", - "Yandex (Russian)"}; + + final List searchEngineList = mSearchEngineProvider.getAllSearchEngines(); + + CharSequence[] chars = convertSearchEngineToString(searchEngineList); int n = mPreferenceManager.getSearchChoice(); @@ -313,8 +337,19 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme @Override public void onClick(DialogInterface dialog, int which) { - mPreferenceManager.setSearchChoice(which); - setSearchEngineSummary(which); + BaseSearchEngine searchEngine = searchEngineList.get(which); + + // Store the search engine preference + int preferencesIndex = mSearchEngineProvider.mapSearchEngineToPreferenceIndex(searchEngine); + mPreferenceManager.setSearchChoice(preferencesIndex); + + if (searchEngine instanceof CustomSearch) { + // Show the URL picker + showUrlPicker((CustomSearch) searchEngine); + } else { + // Set the new search engine summary + setSearchEngineSummary(searchEngine); + } } }); picker.setPositiveButton(R.string.action_ok, null); @@ -549,40 +584,11 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme BrowserDialog.setDialogSize(mActivity, dialog); } - private void setSearchEngineSummary(int which) { - switch (which) { - case 0: - searchUrlPicker(); - break; - case 1: - searchengine.setSummary("Google"); - break; - case 2: - searchengine.setSummary("Ask"); - break; - case 3: - searchengine.setSummary("Bing"); - break; - case 4: - searchengine.setSummary("Yahoo"); - break; - case 5: - searchengine.setSummary("StartPage"); - break; - case 6: - searchengine.setSummary("StartPage (Mobile)"); - break; - case 7: - searchengine.setSummary("DuckDuckGo"); - break; - case 8: - searchengine.setSummary("DuckDuckGo Lite"); - break; - case 9: - searchengine.setSummary("Baidu"); - break; - case 10: - searchengine.setSummary("Yandex"); + private void setSearchEngineSummary(BaseSearchEngine baseSearchEngine) { + if (baseSearchEngine instanceof CustomSearch) { + searchengine.setSummary(mPreferenceManager.getSearchUrl()); + } else { + searchengine.setSummary(getString(baseSearchEngine.getTitleRes())); } } diff --git a/app/src/main/java/acr/browser/lightning/search/SearchEngineProvider.java b/app/src/main/java/acr/browser/lightning/search/SearchEngineProvider.java index 1e27a9f..bf9dd39 100644 --- a/app/src/main/java/acr/browser/lightning/search/SearchEngineProvider.java +++ b/app/src/main/java/acr/browser/lightning/search/SearchEngineProvider.java @@ -2,6 +2,9 @@ package acr.browser.lightning.search; import android.support.annotation.NonNull; +import java.util.ArrayList; +import java.util.List; + import javax.inject.Inject; import acr.browser.lightning.app.BrowserApp; @@ -61,4 +64,49 @@ public class SearchEngineProvider { } } + public int mapSearchEngineToPreferenceIndex(@NonNull BaseSearchEngine searchEngine) { + if (searchEngine instanceof CustomSearch) { + return 0; + } else if (searchEngine instanceof GoogleSearch) { + return 1; + } else if (searchEngine instanceof AskSearch) { + return 2; + } else if (searchEngine instanceof BingSearch) { + return 3; + } else if (searchEngine instanceof YahooSearch) { + return 4; + } else if (searchEngine instanceof StartPageSearch) { + return 5; + } else if (searchEngine instanceof StartPageMobileSearch) { + return 6; + } else if (searchEngine instanceof DuckSearch) { + return 7; + } else if (searchEngine instanceof DuckLiteSearch) { + return 8; + } else if (searchEngine instanceof BaiduSearch) { + return 9; + } else if (searchEngine instanceof YandexSearch) { + return 10; + } else { + throw new UnsupportedOperationException("Unknown search engine provided: " + searchEngine.getClass()); + } + } + + @NonNull + public List getAllSearchEngines() { + return new ArrayList(11) {{ + add(new CustomSearch(mPreferenceManager.getSearchUrl())); + add(new GoogleSearch()); + add(new AskSearch()); + add(new BingSearch()); + add(new YahooSearch()); + add(new StartPageSearch()); + add(new StartPageMobileSearch()); + add(new DuckSearch()); + add(new DuckLiteSearch()); + add(new BaiduSearch()); + add(new YandexSearch()); + }}; + } + } diff --git a/app/src/main/java/acr/browser/lightning/search/engine/AskSearch.java b/app/src/main/java/acr/browser/lightning/search/engine/AskSearch.java index 27aa160..a20c805 100644 --- a/app/src/main/java/acr/browser/lightning/search/engine/AskSearch.java +++ b/app/src/main/java/acr/browser/lightning/search/engine/AskSearch.java @@ -1,5 +1,6 @@ package acr.browser.lightning.search.engine; +import acr.browser.lightning.R; import acr.browser.lightning.constant.Constants; /** @@ -8,7 +9,7 @@ import acr.browser.lightning.constant.Constants; public class AskSearch extends BaseSearchEngine { public AskSearch() { - super("file:///android_asset/ask.png", Constants.ASK_SEARCH); + super("file:///android_asset/ask.png", Constants.ASK_SEARCH, R.string.search_engine_ask); } } diff --git a/app/src/main/java/acr/browser/lightning/search/engine/BaiduSearch.java b/app/src/main/java/acr/browser/lightning/search/engine/BaiduSearch.java index bc46e7d..2f4db83 100644 --- a/app/src/main/java/acr/browser/lightning/search/engine/BaiduSearch.java +++ b/app/src/main/java/acr/browser/lightning/search/engine/BaiduSearch.java @@ -1,5 +1,6 @@ package acr.browser.lightning.search.engine; +import acr.browser.lightning.R; import acr.browser.lightning.constant.Constants; /** @@ -10,7 +11,7 @@ import acr.browser.lightning.constant.Constants; public class BaiduSearch extends BaseSearchEngine { public BaiduSearch() { - super("file:///android_asset/baidu.png", Constants.BAIDU_SEARCH); + super("file:///android_asset/baidu.png", Constants.BAIDU_SEARCH, R.string.search_engine_baidu); } } diff --git a/app/src/main/java/acr/browser/lightning/search/engine/BaseSearchEngine.java b/app/src/main/java/acr/browser/lightning/search/engine/BaseSearchEngine.java index 009d22a..2844ee9 100644 --- a/app/src/main/java/acr/browser/lightning/search/engine/BaseSearchEngine.java +++ b/app/src/main/java/acr/browser/lightning/search/engine/BaseSearchEngine.java @@ -1,23 +1,36 @@ package acr.browser.lightning.search.engine; import android.support.annotation.NonNull; +import android.support.annotation.StringRes; import acr.browser.lightning.utils.Preconditions; /** * A class representative of a search engine. + *

    + * Contains three key pieces of information: + *

      + *
    • The icon shown for the search engine, should point to a local assets URL.
    • + *
    • The query URL for the search engine, the query will be appended to the end.
    • + *
    • The title string resource for the search engine.
    • + *
    */ public class BaseSearchEngine { @NonNull private final String mIconUrl; @NonNull private final String mQueryUrl; + @StringRes private final int mTitleRes; + + public BaseSearchEngine(@NonNull String iconUrl, + @NonNull String queryUrl, + @StringRes int titleRes) { - public BaseSearchEngine(@NonNull String iconUrl, @NonNull String queryUrl) { Preconditions.checkNonNull(iconUrl); Preconditions.checkNonNull(queryUrl); mIconUrl = iconUrl; mQueryUrl = queryUrl; + mTitleRes = titleRes; } @NonNull @@ -30,4 +43,9 @@ public class BaseSearchEngine { return mQueryUrl; } + @StringRes + public final int getTitleRes() { + return mTitleRes; + } + } diff --git a/app/src/main/java/acr/browser/lightning/search/engine/BingSearch.java b/app/src/main/java/acr/browser/lightning/search/engine/BingSearch.java index c3e95dc..3b2d17d 100644 --- a/app/src/main/java/acr/browser/lightning/search/engine/BingSearch.java +++ b/app/src/main/java/acr/browser/lightning/search/engine/BingSearch.java @@ -1,5 +1,6 @@ package acr.browser.lightning.search.engine; +import acr.browser.lightning.R; import acr.browser.lightning.constant.Constants; /** @@ -11,8 +12,7 @@ import acr.browser.lightning.constant.Constants; public class BingSearch extends BaseSearchEngine { public BingSearch() { - super("file:///android_asset/bing.png", Constants.BING_SEARCH); - // "http://upload.wikimedia.org/wikipedia/commons/thumb/b/b1/Bing_logo_%282013%29.svg/500px-Bing_logo_%282013%29.svg.png"; + super("file:///android_asset/bing.png", Constants.BING_SEARCH, R.string.search_engine_bing); } } diff --git a/app/src/main/java/acr/browser/lightning/search/engine/CustomSearch.java b/app/src/main/java/acr/browser/lightning/search/engine/CustomSearch.java index fb7a170..baf6e5c 100644 --- a/app/src/main/java/acr/browser/lightning/search/engine/CustomSearch.java +++ b/app/src/main/java/acr/browser/lightning/search/engine/CustomSearch.java @@ -2,13 +2,15 @@ package acr.browser.lightning.search.engine; import android.support.annotation.NonNull; +import acr.browser.lightning.R; + /** * A custom search engine. */ public class CustomSearch extends BaseSearchEngine { public CustomSearch(@NonNull String queryUrl) { - super("file:///android_asset/lightning.png", queryUrl); + super("file:///android_asset/lightning.png", queryUrl, R.string.search_engine_custom); } } diff --git a/app/src/main/java/acr/browser/lightning/search/engine/DuckLiteSearch.java b/app/src/main/java/acr/browser/lightning/search/engine/DuckLiteSearch.java index 81c2b31..a844031 100644 --- a/app/src/main/java/acr/browser/lightning/search/engine/DuckLiteSearch.java +++ b/app/src/main/java/acr/browser/lightning/search/engine/DuckLiteSearch.java @@ -1,5 +1,6 @@ package acr.browser.lightning.search.engine; +import acr.browser.lightning.R; import acr.browser.lightning.constant.Constants; /** @@ -10,7 +11,7 @@ import acr.browser.lightning.constant.Constants; public class DuckLiteSearch extends BaseSearchEngine { public DuckLiteSearch() { - super("file:///android_asset/duckduckgo.png", Constants.DUCK_LITE_SEARCH); + super("file:///android_asset/duckduckgo.png", Constants.DUCK_LITE_SEARCH, R.string.search_engine_duckduckgo_lite); } } diff --git a/app/src/main/java/acr/browser/lightning/search/engine/DuckSearch.java b/app/src/main/java/acr/browser/lightning/search/engine/DuckSearch.java index cf9d85d..dff9b7d 100644 --- a/app/src/main/java/acr/browser/lightning/search/engine/DuckSearch.java +++ b/app/src/main/java/acr/browser/lightning/search/engine/DuckSearch.java @@ -1,5 +1,6 @@ package acr.browser.lightning.search.engine; +import acr.browser.lightning.R; import acr.browser.lightning.constant.Constants; /** @@ -10,7 +11,7 @@ import acr.browser.lightning.constant.Constants; public class DuckSearch extends BaseSearchEngine { public DuckSearch() { - super("file:///android_asset/duckduckgo.png", Constants.DUCK_SEARCH); + super("file:///android_asset/duckduckgo.png", Constants.DUCK_SEARCH, R.string.search_engine_duckduckgo); } } diff --git a/app/src/main/java/acr/browser/lightning/search/engine/GoogleSearch.java b/app/src/main/java/acr/browser/lightning/search/engine/GoogleSearch.java index ef08792..efa6def 100644 --- a/app/src/main/java/acr/browser/lightning/search/engine/GoogleSearch.java +++ b/app/src/main/java/acr/browser/lightning/search/engine/GoogleSearch.java @@ -1,5 +1,6 @@ package acr.browser.lightning.search.engine; +import acr.browser.lightning.R; import acr.browser.lightning.constant.Constants; /** @@ -10,6 +11,6 @@ import acr.browser.lightning.constant.Constants; public class GoogleSearch extends BaseSearchEngine { public GoogleSearch() { - super("file:///android_asset/google.png", Constants.GOOGLE_SEARCH); + super("file:///android_asset/google.png", Constants.GOOGLE_SEARCH, R.string.search_engine_google); } } diff --git a/app/src/main/java/acr/browser/lightning/search/engine/StartPageMobileSearch.java b/app/src/main/java/acr/browser/lightning/search/engine/StartPageMobileSearch.java index e150874..a961339 100644 --- a/app/src/main/java/acr/browser/lightning/search/engine/StartPageMobileSearch.java +++ b/app/src/main/java/acr/browser/lightning/search/engine/StartPageMobileSearch.java @@ -1,5 +1,6 @@ package acr.browser.lightning.search.engine; +import acr.browser.lightning.R; import acr.browser.lightning.constant.Constants; /** @@ -8,7 +9,7 @@ import acr.browser.lightning.constant.Constants; public class StartPageMobileSearch extends BaseSearchEngine { public StartPageMobileSearch() { - super("file:///android_asset/startpage.png", Constants.STARTPAGE_MOBILE_SEARCH); + super("file:///android_asset/startpage.png", Constants.STARTPAGE_MOBILE_SEARCH, R.string.search_engine_startpage_mobile); } } diff --git a/app/src/main/java/acr/browser/lightning/search/engine/StartPageSearch.java b/app/src/main/java/acr/browser/lightning/search/engine/StartPageSearch.java index ef84bc1..bd48e50 100644 --- a/app/src/main/java/acr/browser/lightning/search/engine/StartPageSearch.java +++ b/app/src/main/java/acr/browser/lightning/search/engine/StartPageSearch.java @@ -1,5 +1,6 @@ package acr.browser.lightning.search.engine; +import acr.browser.lightning.R; import acr.browser.lightning.constant.Constants; /** @@ -8,7 +9,7 @@ import acr.browser.lightning.constant.Constants; public class StartPageSearch extends BaseSearchEngine { public StartPageSearch() { - super("file:///android_asset/startpage.png", Constants.STARTPAGE_SEARCH); + super("file:///android_asset/startpage.png", Constants.STARTPAGE_SEARCH, R.string.search_engine_startpage); } } diff --git a/app/src/main/java/acr/browser/lightning/search/engine/YahooSearch.java b/app/src/main/java/acr/browser/lightning/search/engine/YahooSearch.java index 8bfec27..74b1a81 100644 --- a/app/src/main/java/acr/browser/lightning/search/engine/YahooSearch.java +++ b/app/src/main/java/acr/browser/lightning/search/engine/YahooSearch.java @@ -1,5 +1,6 @@ package acr.browser.lightning.search.engine; +import acr.browser.lightning.R; import acr.browser.lightning.constant.Constants; /** @@ -11,7 +12,7 @@ import acr.browser.lightning.constant.Constants; public class YahooSearch extends BaseSearchEngine { public YahooSearch() { - super("file:///android_asset/yahoo.png", Constants.YAHOO_SEARCH); + super("file:///android_asset/yahoo.png", Constants.YAHOO_SEARCH, R.string.search_engine_yahoo); } } diff --git a/app/src/main/java/acr/browser/lightning/search/engine/YandexSearch.java b/app/src/main/java/acr/browser/lightning/search/engine/YandexSearch.java index 917fd63..ff746e7 100644 --- a/app/src/main/java/acr/browser/lightning/search/engine/YandexSearch.java +++ b/app/src/main/java/acr/browser/lightning/search/engine/YandexSearch.java @@ -1,5 +1,6 @@ package acr.browser.lightning.search.engine; +import acr.browser.lightning.R; import acr.browser.lightning.constant.Constants; /** @@ -11,7 +12,7 @@ import acr.browser.lightning.constant.Constants; public class YandexSearch extends BaseSearchEngine { public YandexSearch() { - super("file:///android_asset/yandex.png", Constants.YANDEX_SEARCH); + super("file:///android_asset/yandex.png", Constants.YANDEX_SEARCH, R.string.search_engine_yandex); } } diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 7cc7b91..01714c4 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -119,7 +119,7 @@ Maximale Reiteranzahl erreicht! Text in Zwischenablage kopiert Link in Zwischenablage kopiert - Benutzerdefinierte URL + Benutzerdefinierte URL Lokale Datei wurde beim Laden blockiert Open Source-Lizenzen Suche nach diff --git a/app/src/main/res/values-el/strings.xml b/app/src/main/res/values-el/strings.xml index 42e1d34..aaa3dbe 100644 --- a/app/src/main/res/values-el/strings.xml +++ b/app/src/main/res/values-el/strings.xml @@ -103,7 +103,7 @@ Μέγιστος αριθμός καρτελών ξεπεράστηκε Το κείμενο αντιγράφτηκε Ο σύνδεσμος αντιγράφτηκε - Ειδικό URL + Ειδικό URL Τοπικά αρχεία εχουν μπλοκαριστεί απο την φόρτωση Άδειες ανοιχτού κώδικα Αναζήτηση για diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 581cf5c..5498448 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -103,7 +103,7 @@ Se ha alcanzado el máximo de pestañas El texto se ha copiado al portapapeles El enlace se ha copiado al portapapeles - Dirección personalizada + Dirección personalizada Se ha bloqueado la carga del archivo local Licencias de código abierto (open source) Buscar diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 2ca2c67..b48d517 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -125,7 +125,7 @@ Onglets maximuns atteint Texte copié dans le presse-papiers Adresse copiée dans le presse-papiers - Adresse personnalisée + Adresse personnalisée Le fichier local a été bloqué au chargement Licences open source Recherche diff --git a/app/src/main/res/values-hu/strings.xml b/app/src/main/res/values-hu/strings.xml index 49197e5..73e5026 100644 --- a/app/src/main/res/values-hu/strings.xml +++ b/app/src/main/res/values-hu/strings.xml @@ -124,7 +124,7 @@ Maximálisan megnyitható lapok száma elérve Szöveg másolva a vágólapra Link másolva a vágólapra - Egyéni URL + Egyéni URL Helyi fájl betöltése blokkolva Nyílt forráskódú licencek Keresés diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 453b540..5e5def1 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -124,7 +124,7 @@ Hai raggiunto il numero massimo di schede apribili Testo copiato negli appunti Link copiato negli appunti - URL personalizzato + URL personalizzato Caricamento file locale bloccato Licenze Open Source Cerca diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 7560a81..06edf96 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -110,7 +110,7 @@ これ以上タブは開けません テキストをクリップボードにコピーしました リンクをクリップボードにコピーしました - カスタム URL + カスタム URL ファイルを読み込めませんでした オープンソース ライセンス 検索 : diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml index b1c7371..05193e1 100644 --- a/app/src/main/res/values-ko/strings.xml +++ b/app/src/main/res/values-ko/strings.xml @@ -102,7 +102,7 @@ 최대 탭 수에 도달했습니다 텍스트가 클립보드로 복사되었습니다 링크가 클립보드로 복사되었습니다 - 임의의 URL + 임의의 URL 로컬 파일 불러오기가 차단되었습니다 오픈 소스 라이센스 다음을 검색 diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index 1220d29..ee20abd 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -124,7 +124,7 @@ Maximum aantal tabbladen bereikt Tekst gekopieerd naar klembord Link gekopieerd naar klembord - Aangepaste URL + Aangepaste URL Lokaal bestand werd geblokkeerd Open Source Licenses Zoek voor diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 16fc7bc..f97ab38 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -105,7 +105,7 @@ Maksymalna liczba otwartych kart osiągnięta Tekst został skopiowany do schowka Link został skopiowany do schowka - Własny URL + Własny URL Wczytywanie lokalnego pliku zostało zablokowane Licencje Open Source Wyszukaj diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index e19b5d9..0a4976b 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -118,7 +118,7 @@ Atingido número máximo de abas Texto copiado para a área de transferência Link copiado para a área de transferência - URL personalizado + URL personalizado Bloqueado o carregamento do arquivo local Licenças Open Source Pesquisar por diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index ba43569..42d1c35 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -123,7 +123,7 @@ Atingido o número máximo de separadores Texto copiado para a área de transferência Ligação copiada para a área de transferência - URL personalizado + URL personalizado Bloqueado o carregamento do ficheiro local Licenças Open Source Pesquisar por diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index c55010b..dc0d453 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -107,7 +107,7 @@ Достигнуто максимальное число вкладок Текст скопирован в буфер обмена Ссылка скопирована в буфер обмена - Пользовательский URL + Пользовательский URL Локальный файл недоступен для загрузки Open Source Licenses Искать diff --git a/app/src/main/res/values-sr/strings.xml b/app/src/main/res/values-sr/strings.xml index f4324a1..1206ed3 100644 --- a/app/src/main/res/values-sr/strings.xml +++ b/app/src/main/res/values-sr/strings.xml @@ -124,7 +124,7 @@ Досегнут макс. број језичака Текст копиран на клипборд Веза копирана на клипборд - Посебна адреса + Посебна адреса Учитавање локалног фајла је блокирано Лиценце отвореног кôда Тражи diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml index a70a21b..d550bf1 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -108,7 +108,7 @@ Maksimum sekme sınırına ulaşıldı Yazı panoya kopyalandı Bağlantı panoya kopyalandı - Kişisel bağlantı + Kişisel bağlantı Yerel dosyanın yüklenmesi engellendi Açık Kaynak Lisansları Ara diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index a947e3f..943dc61 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -102,7 +102,7 @@ 达到最大标签数 文本已复制到剪贴板 链接已复制到剪贴板 - 自定义 URL + 自定义 URL 本地文件已被阻止加载 开源许可 搜索目标 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 3961f2a..5cb683c 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -102,7 +102,7 @@ 達到最大標籤數 文本已複製到剪貼板 鏈接已複製到剪貼板 - 自定義 URL + 自定義 URL 本地檔已被阻止加載 開源許可 搜索目標 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c890aa0..2e8b2a7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -110,7 +110,6 @@ Max tabs reached Text copied to clipboard Link copied to clipboard - Custom URL Local file has been blocked from loading Open Source Licenses Search for @@ -253,4 +252,17 @@ Close browser Delete download Delete all downloads + + + Custom URL + Google + Ask + Bing + Yahoo + StartPage + StartPage Mobile + DuckDuckGo + DuckDuckGo Lite + Baidu + Yandex From 58dac82e7a1b149da95ed4e812285a3453dc73ac Mon Sep 17 00:00:00 2001 From: anthony restaino Date: Fri, 23 Jun 2017 23:31:22 -0400 Subject: [PATCH 41/56] Moving search suggestions into their own package --- .../lightning/search/SuggestionsManager.java | 9 +++-- .../BaiduSuggestionsModel.java | 13 +++--- .../BaseSuggestionsModel.java | 40 ++++++++++++------- .../DuckSuggestionsModel.java | 6 +-- .../GoogleSuggestionsModel.java | 6 +-- 5 files changed, 43 insertions(+), 31 deletions(-) rename app/src/main/java/acr/browser/lightning/search/{ => suggestions}/BaiduSuggestionsModel.java (81%) rename app/src/main/java/acr/browser/lightning/search/{ => suggestions}/BaseSuggestionsModel.java (89%) rename app/src/main/java/acr/browser/lightning/search/{ => suggestions}/DuckSuggestionsModel.java (88%) rename app/src/main/java/acr/browser/lightning/search/{ => suggestions}/GoogleSuggestionsModel.java (92%) diff --git a/app/src/main/java/acr/browser/lightning/search/SuggestionsManager.java b/app/src/main/java/acr/browser/lightning/search/SuggestionsManager.java index 13edb8c..90bbf6b 100644 --- a/app/src/main/java/acr/browser/lightning/search/SuggestionsManager.java +++ b/app/src/main/java/acr/browser/lightning/search/SuggestionsManager.java @@ -10,6 +10,9 @@ import com.anthonycr.bonsai.SingleSubscriber; import java.util.List; import acr.browser.lightning.database.HistoryItem; +import acr.browser.lightning.search.suggestions.BaiduSuggestionsModel; +import acr.browser.lightning.search.suggestions.DuckSuggestionsModel; +import acr.browser.lightning.search.suggestions.GoogleSuggestionsModel; class SuggestionsManager { @@ -26,7 +29,7 @@ class SuggestionsManager { @Override public void onSubscribe(@NonNull final SingleSubscriber> subscriber) { sIsTaskExecuting = true; - List results = new GoogleSuggestionsModel(application).getResults(query); + List results = new GoogleSuggestionsModel(application).fetchResults(query); subscriber.onItem(results); subscriber.onComplete(); sIsTaskExecuting = false; @@ -41,7 +44,7 @@ class SuggestionsManager { @Override public void onSubscribe(@NonNull final SingleSubscriber> subscriber) { sIsTaskExecuting = true; - List results = new BaiduSuggestionsModel(application).getResults(query); + List results = new BaiduSuggestionsModel(application).fetchResults(query); subscriber.onItem(results); subscriber.onComplete(); sIsTaskExecuting = false; @@ -56,7 +59,7 @@ class SuggestionsManager { @Override public void onSubscribe(@NonNull final SingleSubscriber> subscriber) { sIsTaskExecuting = true; - List results = new DuckSuggestionsModel(application).getResults(query); + List results = new DuckSuggestionsModel(application).fetchResults(query); subscriber.onItem(results); subscriber.onComplete(); sIsTaskExecuting = false; diff --git a/app/src/main/java/acr/browser/lightning/search/BaiduSuggestionsModel.java b/app/src/main/java/acr/browser/lightning/search/suggestions/BaiduSuggestionsModel.java similarity index 81% rename from app/src/main/java/acr/browser/lightning/search/BaiduSuggestionsModel.java rename to app/src/main/java/acr/browser/lightning/search/suggestions/BaiduSuggestionsModel.java index 412bfd8..15ff881 100644 --- a/app/src/main/java/acr/browser/lightning/search/BaiduSuggestionsModel.java +++ b/app/src/main/java/acr/browser/lightning/search/suggestions/BaiduSuggestionsModel.java @@ -1,11 +1,9 @@ -package acr.browser.lightning.search; +package acr.browser.lightning.search.suggestions; import android.app.Application; import android.support.annotation.NonNull; -import android.support.annotation.Nullable; import org.json.JSONArray; -import org.xmlpull.v1.XmlPullParser; import java.io.InputStream; import java.util.List; @@ -18,13 +16,12 @@ import acr.browser.lightning.utils.FileUtils; // http://suggestion.baidu.com/s?wd=encodeURIComponent(U)&action=opensearch -class BaiduSuggestionsModel extends BaseSuggestionsModel { +public class BaiduSuggestionsModel extends BaseSuggestionsModel { @NonNull private static final String ENCODING = "UTF-8"; - @Nullable private static XmlPullParser sXpp; @NonNull private final String mSearchSubtitle; - BaiduSuggestionsModel(@NonNull Application application) { + public BaiduSuggestionsModel(@NonNull Application application) { super(application, ENCODING); mSearchSubtitle = application.getString(R.string.suggestion); } @@ -39,12 +36,14 @@ class BaiduSuggestionsModel extends BaseSuggestionsModel { String content = FileUtils.readStringFromStream(inputStream, "GBK"); JSONArray respArray = new JSONArray(content); JSONArray jsonArray = respArray.getJSONArray(1); + int counter = 0; for (int n = 0, size = jsonArray.length(); n < size; n++) { String suggestion = jsonArray.getString(n); results.add(new HistoryItem(mSearchSubtitle + " \"" + suggestion + '"', - suggestion, R.drawable.ic_search)); + suggestion, R.drawable.ic_search)); counter++; + if (counter >= MAX_RESULTS) { break; } diff --git a/app/src/main/java/acr/browser/lightning/search/BaseSuggestionsModel.java b/app/src/main/java/acr/browser/lightning/search/suggestions/BaseSuggestionsModel.java similarity index 89% rename from app/src/main/java/acr/browser/lightning/search/BaseSuggestionsModel.java rename to app/src/main/java/acr/browser/lightning/search/suggestions/BaseSuggestionsModel.java index 7dfcf47..8a86196 100644 --- a/app/src/main/java/acr/browser/lightning/search/BaseSuggestionsModel.java +++ b/app/src/main/java/acr/browser/lightning/search/suggestions/BaseSuggestionsModel.java @@ -1,4 +1,4 @@ -package acr.browser.lightning.search; +package acr.browser.lightning.search.suggestions; import android.app.Application; import android.support.annotation.NonNull; @@ -28,7 +28,7 @@ import okhttp3.Request; import okhttp3.Response; import okhttp3.ResponseBody; -abstract class BaseSuggestionsModel { +public abstract class BaseSuggestionsModel { private static final String TAG = "BaseSuggestionsModel"; @@ -57,23 +57,25 @@ abstract class BaseSuggestionsModel { mCacheControl = new CacheControl.Builder().maxStale(1, TimeUnit.DAYS).build(); } + /** + * Retrieves the results for a query. + * + * @param rawQuery the raw query to retrieve the results for. + * @return a list of history items for the query. + */ @NonNull - private static String getLanguage() { - String language = Locale.getDefault().getLanguage(); - if (TextUtils.isEmpty(language)) { - language = DEFAULT_LANGUAGE; - } - return language; - } - - @NonNull - List getResults(@NonNull String query) { + public final List fetchResults(@NonNull final String rawQuery) { List filter = new ArrayList<>(5); + + String query; try { - query = URLEncoder.encode(query, mEncoding); + query = URLEncoder.encode(rawQuery, mEncoding); } catch (UnsupportedEncodingException e) { Log.e(TAG, "Unable to encode the URL", e); + + return filter; } + InputStream inputStream = downloadSuggestionsForQuery(query, mLanguage); if (inputStream == null) { // There are no suggestions for this query, return an empty list. @@ -83,7 +85,6 @@ abstract class BaseSuggestionsModel { parseResults(inputStream, filter); } catch (Exception e) { Log.e(TAG, "Unable to parse results", e); - return filter; } finally { Utils.close(inputStream); } @@ -93,7 +94,7 @@ abstract class BaseSuggestionsModel { /** * This method downloads the search suggestions for the specific query. - * NOTE: This is a blocking operation, do not getResults on the UI thread. + * NOTE: This is a blocking operation, do not fetchResults on the UI thread. * * @param query the query to get suggestions for * @return the cache file containing the suggestions @@ -122,6 +123,15 @@ abstract class BaseSuggestionsModel { return null; } + @NonNull + private static String getLanguage() { + String language = Locale.getDefault().getLanguage(); + if (TextUtils.isEmpty(language)) { + language = DEFAULT_LANGUAGE; + } + return language; + } + private static final Interceptor REWRITE_CACHE_CONTROL_INTERCEPTOR = new Interceptor() { @Override public Response intercept(@NonNull Chain chain) throws IOException { diff --git a/app/src/main/java/acr/browser/lightning/search/DuckSuggestionsModel.java b/app/src/main/java/acr/browser/lightning/search/suggestions/DuckSuggestionsModel.java similarity index 88% rename from app/src/main/java/acr/browser/lightning/search/DuckSuggestionsModel.java rename to app/src/main/java/acr/browser/lightning/search/suggestions/DuckSuggestionsModel.java index b07b303..89b55dd 100644 --- a/app/src/main/java/acr/browser/lightning/search/DuckSuggestionsModel.java +++ b/app/src/main/java/acr/browser/lightning/search/suggestions/DuckSuggestionsModel.java @@ -1,4 +1,4 @@ -package acr.browser.lightning.search; +package acr.browser.lightning.search.suggestions; import android.app.Application; import android.support.annotation.NonNull; @@ -13,12 +13,12 @@ import acr.browser.lightning.R; import acr.browser.lightning.database.HistoryItem; import acr.browser.lightning.utils.FileUtils; -final class DuckSuggestionsModel extends BaseSuggestionsModel { +public final class DuckSuggestionsModel extends BaseSuggestionsModel { @NonNull private static final String ENCODING = "UTF-8"; @NonNull private final String mSearchSubtitle; - DuckSuggestionsModel(@NonNull Application application) { + public DuckSuggestionsModel(@NonNull Application application) { super(application, ENCODING); mSearchSubtitle = application.getString(R.string.suggestion); } diff --git a/app/src/main/java/acr/browser/lightning/search/GoogleSuggestionsModel.java b/app/src/main/java/acr/browser/lightning/search/suggestions/GoogleSuggestionsModel.java similarity index 92% rename from app/src/main/java/acr/browser/lightning/search/GoogleSuggestionsModel.java rename to app/src/main/java/acr/browser/lightning/search/suggestions/GoogleSuggestionsModel.java index ed892a0..40321e9 100644 --- a/app/src/main/java/acr/browser/lightning/search/GoogleSuggestionsModel.java +++ b/app/src/main/java/acr/browser/lightning/search/suggestions/GoogleSuggestionsModel.java @@ -1,4 +1,4 @@ -package acr.browser.lightning.search; +package acr.browser.lightning.search.suggestions; import android.app.Application; import android.support.annotation.NonNull; @@ -15,13 +15,13 @@ import java.util.List; import acr.browser.lightning.R; import acr.browser.lightning.database.HistoryItem; -class GoogleSuggestionsModel extends BaseSuggestionsModel { +public class GoogleSuggestionsModel extends BaseSuggestionsModel { @NonNull private static final String ENCODING = "ISO-8859-1"; @Nullable private static XmlPullParser sXpp; @NonNull private final String mSearchSubtitle; - GoogleSuggestionsModel(@NonNull Application application) { + public GoogleSuggestionsModel(@NonNull Application application) { super(application, ENCODING); mSearchSubtitle = application.getString(R.string.suggestion); } From 83099dc90dd0e63234a8623339a713e7af69bec8 Mon Sep 17 00:00:00 2001 From: anthony restaino Date: Fri, 23 Jun 2017 23:36:30 -0400 Subject: [PATCH 42/56] Cleaning up documentation --- .../suggestions/BaiduSuggestionsModel.java | 9 +++++---- .../suggestions/BaseSuggestionsModel.java | 19 +++++++++++++++++++ .../suggestions/DuckSuggestionsModel.java | 3 +++ .../suggestions/GoogleSuggestionsModel.java | 3 +++ 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/acr/browser/lightning/search/suggestions/BaiduSuggestionsModel.java b/app/src/main/java/acr/browser/lightning/search/suggestions/BaiduSuggestionsModel.java index 15ff881..2c18ec3 100644 --- a/app/src/main/java/acr/browser/lightning/search/suggestions/BaiduSuggestionsModel.java +++ b/app/src/main/java/acr/browser/lightning/search/suggestions/BaiduSuggestionsModel.java @@ -12,10 +12,9 @@ import acr.browser.lightning.R; import acr.browser.lightning.database.HistoryItem; import acr.browser.lightning.utils.FileUtils; -// http://unionsug.baidu.com/su?wd=encodeURIComponent(U) -// http://suggestion.baidu.com/s?wd=encodeURIComponent(U)&action=opensearch - - +/** + * The search suggestions provider for the Baidu search engine. + */ public class BaiduSuggestionsModel extends BaseSuggestionsModel { @NonNull private static final String ENCODING = "UTF-8"; @@ -28,6 +27,8 @@ public class BaiduSuggestionsModel extends BaseSuggestionsModel { @NonNull protected String createQueryUrl(@NonNull String query, @NonNull String language) { + // see http://unionsug.baidu.com/su?wd=encodeURIComponent(U) + // see http://suggestion.baidu.com/s?wd=encodeURIComponent(U)&action=opensearch return "http://suggestion.baidu.com/s?wd=" + query + "&action=opensearch"; } diff --git a/app/src/main/java/acr/browser/lightning/search/suggestions/BaseSuggestionsModel.java b/app/src/main/java/acr/browser/lightning/search/suggestions/BaseSuggestionsModel.java index 8a86196..34abde6 100644 --- a/app/src/main/java/acr/browser/lightning/search/suggestions/BaseSuggestionsModel.java +++ b/app/src/main/java/acr/browser/lightning/search/suggestions/BaseSuggestionsModel.java @@ -28,6 +28,11 @@ import okhttp3.Request; import okhttp3.Response; import okhttp3.ResponseBody; +/** + * The base search suggestions API. Provides common + * fetching and caching functionality for each potential + * suggestions provider. + */ public abstract class BaseSuggestionsModel { private static final String TAG = "BaseSuggestionsModel"; @@ -41,9 +46,23 @@ public abstract class BaseSuggestionsModel { @NonNull private final String mEncoding; @NonNull private final String mLanguage; + /** + * Create a URL for the given query in the given language. + * + * @param query the query that was made. + * @param language the locale of the user. + * @return should return a URL that can be fetched using a GET. + */ @NonNull protected abstract String createQueryUrl(@NonNull String query, @NonNull String language); + /** + * Parse the results of an input stream into a list of {@link HistoryItem}. + * + * @param inputStream the raw input to parse. + * @param results the list to populate. + * @throws Exception throw an exception if anything goes wrong. + */ protected abstract void parseResults(@NonNull InputStream inputStream, @NonNull List results) throws Exception; BaseSuggestionsModel(@NonNull Application application, @NonNull String encoding) { diff --git a/app/src/main/java/acr/browser/lightning/search/suggestions/DuckSuggestionsModel.java b/app/src/main/java/acr/browser/lightning/search/suggestions/DuckSuggestionsModel.java index 89b55dd..91f6f56 100644 --- a/app/src/main/java/acr/browser/lightning/search/suggestions/DuckSuggestionsModel.java +++ b/app/src/main/java/acr/browser/lightning/search/suggestions/DuckSuggestionsModel.java @@ -13,6 +13,9 @@ import acr.browser.lightning.R; import acr.browser.lightning.database.HistoryItem; import acr.browser.lightning.utils.FileUtils; +/** + * The search suggestions provider for the DuckDuckGo search engine. + */ public final class DuckSuggestionsModel extends BaseSuggestionsModel { @NonNull private static final String ENCODING = "UTF-8"; diff --git a/app/src/main/java/acr/browser/lightning/search/suggestions/GoogleSuggestionsModel.java b/app/src/main/java/acr/browser/lightning/search/suggestions/GoogleSuggestionsModel.java index 40321e9..1128766 100644 --- a/app/src/main/java/acr/browser/lightning/search/suggestions/GoogleSuggestionsModel.java +++ b/app/src/main/java/acr/browser/lightning/search/suggestions/GoogleSuggestionsModel.java @@ -15,6 +15,9 @@ import java.util.List; import acr.browser.lightning.R; import acr.browser.lightning.database.HistoryItem; +/** + * Search suggestions provider for Google search engine. + */ public class GoogleSuggestionsModel extends BaseSuggestionsModel { @NonNull private static final String ENCODING = "ISO-8859-1"; From 4e4707b524936e702829856f0419b02198ae95cd Mon Sep 17 00:00:00 2001 From: anthony restaino Date: Sat, 24 Jun 2017 22:19:40 -0400 Subject: [PATCH 43/56] Cleaning up code --- .../browser/lightning/database/HistoryItem.java | 16 ++++++---------- .../database/downloads/DownloadItem.java | 9 +++------ .../search/engine/BaseSearchEngine.java | 6 +++--- .../search/suggestions/BaseSuggestionsModel.java | 1 + .../lightning/utils/StringBuilderUtils.java | 8 ++++---- 5 files changed, 17 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/acr/browser/lightning/database/HistoryItem.java b/app/src/main/java/acr/browser/lightning/database/HistoryItem.java index 7913864..69d61a1 100644 --- a/app/src/main/java/acr/browser/lightning/database/HistoryItem.java +++ b/app/src/main/java/acr/browser/lightning/database/HistoryItem.java @@ -12,11 +12,8 @@ import acr.browser.lightning.utils.Preconditions; public class HistoryItem implements Comparable { @NonNull private String mUrl = ""; - @NonNull private String mTitle = ""; - @NonNull private String mFolder = ""; - @Nullable private Bitmap mBitmap = null; private int mImageId = 0; @@ -126,13 +123,12 @@ public class HistoryItem implements Comparable { HistoryItem that = (HistoryItem) o; - if (mImageId != that.mImageId) return false; - if (mPosition != that.mPosition) return false; - if (mIsFolder != that.mIsFolder) return false; - if (!mUrl.equals(that.mUrl)) return false; - if (!mTitle.equals(that.mTitle)) return false; - - return mFolder.equals(that.mFolder); + return mImageId == that.mImageId && + mPosition == that.mPosition && + mIsFolder == that.mIsFolder && + mUrl.equals(that.mUrl) && + mTitle.equals(that.mTitle) && + mFolder.equals(that.mFolder); } diff --git a/app/src/main/java/acr/browser/lightning/database/downloads/DownloadItem.java b/app/src/main/java/acr/browser/lightning/database/downloads/DownloadItem.java index b45abb6..6585f35 100644 --- a/app/src/main/java/acr/browser/lightning/database/downloads/DownloadItem.java +++ b/app/src/main/java/acr/browser/lightning/database/downloads/DownloadItem.java @@ -11,9 +11,7 @@ import acr.browser.lightning.utils.Preconditions; public class DownloadItem implements Comparable { @NonNull private String mUrl = ""; - @NonNull private String mTitle = ""; - @NonNull private String mContentSize = ""; public DownloadItem() {} @@ -76,10 +74,9 @@ public class DownloadItem implements Comparable { DownloadItem that = (DownloadItem) o; - if (!mUrl.equals(that.mUrl)) return false; - if (!mTitle.equals(that.mTitle)) return false; - - return mContentSize.equals(that.mContentSize); + return mUrl.equals(that.mUrl) && + mTitle.equals(that.mTitle) && + mContentSize.equals(that.mContentSize); } diff --git a/app/src/main/java/acr/browser/lightning/search/engine/BaseSearchEngine.java b/app/src/main/java/acr/browser/lightning/search/engine/BaseSearchEngine.java index 2844ee9..92cb5e9 100644 --- a/app/src/main/java/acr/browser/lightning/search/engine/BaseSearchEngine.java +++ b/app/src/main/java/acr/browser/lightning/search/engine/BaseSearchEngine.java @@ -21,9 +21,9 @@ public class BaseSearchEngine { @NonNull private final String mQueryUrl; @StringRes private final int mTitleRes; - public BaseSearchEngine(@NonNull String iconUrl, - @NonNull String queryUrl, - @StringRes int titleRes) { + BaseSearchEngine(@NonNull String iconUrl, + @NonNull String queryUrl, + @StringRes int titleRes) { Preconditions.checkNonNull(iconUrl); Preconditions.checkNonNull(queryUrl); diff --git a/app/src/main/java/acr/browser/lightning/search/suggestions/BaseSuggestionsModel.java b/app/src/main/java/acr/browser/lightning/search/suggestions/BaseSuggestionsModel.java index 34abde6..961715f 100644 --- a/app/src/main/java/acr/browser/lightning/search/suggestions/BaseSuggestionsModel.java +++ b/app/src/main/java/acr/browser/lightning/search/suggestions/BaseSuggestionsModel.java @@ -151,6 +151,7 @@ public abstract class BaseSuggestionsModel { return language; } + @NonNull private static final Interceptor REWRITE_CACHE_CONTROL_INTERCEPTOR = new Interceptor() { @Override public Response intercept(@NonNull Chain chain) throws IOException { diff --git a/app/src/main/java/acr/browser/lightning/utils/StringBuilderUtils.java b/app/src/main/java/acr/browser/lightning/utils/StringBuilderUtils.java index 0c66f8a..77c5bb7 100644 --- a/app/src/main/java/acr/browser/lightning/utils/StringBuilderUtils.java +++ b/app/src/main/java/acr/browser/lightning/utils/StringBuilderUtils.java @@ -8,7 +8,7 @@ import android.support.annotation.NonNull; * API equality with the {@link String} * API. */ -public class StringBuilderUtils { +class StringBuilderUtils { private static final String SPACE = " "; private static final String EMPTY = ""; @@ -21,9 +21,9 @@ public class StringBuilderUtils { * @param toReplace the string to replace. * @param replacement the replacement string. */ - public static void replace(@NonNull StringBuilder stringBuilder, - @NonNull String toReplace, - @NonNull String replacement) { + static void replace(@NonNull StringBuilder stringBuilder, + @NonNull String toReplace, + @NonNull String replacement) { int index = stringBuilder.indexOf(toReplace); if (index >= 0) { stringBuilder.replace(index, index + toReplace.length(), replacement); From 1b1ce0726c6b074d5c1ed8b929ee43e521f7b99b Mon Sep 17 00:00:00 2001 From: anthony restaino Date: Sat, 24 Jun 2017 22:19:57 -0400 Subject: [PATCH 44/56] Cleaning up redundant initializers --- .../java/acr/browser/lightning/activity/BrowserActivity.java | 2 +- .../main/java/acr/browser/lightning/reading/HtmlFetcher.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java b/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java index d2767c1..454478d 100644 --- a/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java +++ b/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java @@ -747,7 +747,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements } return true; case KeyEvent.KEYCODE_TAB: - int nextIndex = 0; + int nextIndex; if (event.isShiftPressed()) { // Go back one tab if (mTabsManager.indexOfCurrentTab() > 0) { diff --git a/app/src/main/java/acr/browser/lightning/reading/HtmlFetcher.java b/app/src/main/java/acr/browser/lightning/reading/HtmlFetcher.java index 85a1862..f49b815 100644 --- a/app/src/main/java/acr/browser/lightning/reading/HtmlFetcher.java +++ b/app/src/main/java/acr/browser/lightning/reading/HtmlFetcher.java @@ -376,8 +376,8 @@ public class HtmlFetcher { */ private String getResolvedUrl(String urlAsString, int timeout, int num_redirects) { - String newUrl = null; - int responseCode = -1; + String newUrl; + int responseCode; try { HttpURLConnection hConn = createUrlConnection(urlAsString, timeout, true); // force no follow From 926ffcb569185a01db74aae3945d43689640d9e3 Mon Sep 17 00:00:00 2001 From: Anthony Restaino Date: Sun, 25 Jun 2017 19:21:48 -0400 Subject: [PATCH 45/56] Changing download options --- README.md | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 43a7f3b..1188997 100644 --- a/README.md +++ b/README.md @@ -4,13 +4,12 @@ ![](ic_launcher_small.png) #### Download -* [Download APK from here](https://github.com/anthonycr/Lightning-Browser/releases) - -* [Download from F-Droid](https://f-droid.org/repository/browse/?fdfilter=lightning&fdid=acr.browser.lightning) - -* [Download Free from Google Play](https://play.google.com/store/apps/details?id=acr.browser.barebones) - -* [Download Paid from Google Play](https://play.google.com/store/apps/details?id=acr.browser.lightning) +[Get it on F-Droid](https://f-droid.org/app/acr.browser.lightning) + +[](https://play.google.com/store/apps/details?id=acr.browser.lightning) #### Master Branch * [![Build Status](https://travis-ci.org/anthonycr/Lightning-Browser.svg?branch=master)](https://travis-ci.org/anthonycr/Lightning-Browser) From fc70eff4f36d3c6a3445bc66471ca9ed229c9917 Mon Sep 17 00:00:00 2001 From: Anthony Restaino Date: Sun, 25 Jun 2017 19:22:22 -0400 Subject: [PATCH 46/56] Updating formatting --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 1188997..5c4d40c 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,7 @@ #### Download [Get it on F-Droid](https://f-droid.org/app/acr.browser.lightning) - -[](https://f-droid.org/app/acr.browser.lightning) [Get it on Google Play](https://play.google.com/store/apps/details?id=acr.browser.lightning) #### Master Branch From 4389cf99857e1e30879c45d6137d068ebab41fde Mon Sep 17 00:00:00 2001 From: Mohit Sarveiya Date: Mon, 26 Jun 2017 21:55:04 -0400 Subject: [PATCH 47/56] Added Kotlin to project and converted SearchSuggestionManager to Kotlin --- app/build.gradle | 4 ++ .../lightning/search/SuggestionsAdapter.java | 6 +- .../lightning/search/SuggestionsManager.java | 70 ------------------- .../lightning/search/SuggestionsManager.kt | 43 ++++++++++++ build.gradle | 2 + 5 files changed, 52 insertions(+), 73 deletions(-) delete mode 100644 app/src/main/java/acr/browser/lightning/search/SuggestionsManager.java create mode 100644 app/src/main/java/acr/browser/lightning/search/SuggestionsManager.kt diff --git a/app/build.gradle b/app/build.gradle index be9f680..beb699b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,4 +1,5 @@ apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' apply plugin: 'com.getkeepsafe.dexcount' android { @@ -108,4 +109,7 @@ dependencies { def leakCanaryVersion = '1.5.1' debugCompile "com.squareup.leakcanary:leakcanary-android:$leakCanaryVersion" releaseCompile "com.squareup.leakcanary:leakcanary-android-no-op:$leakCanaryVersion" + + // Kotlin + compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" } diff --git a/app/src/main/java/acr/browser/lightning/search/SuggestionsAdapter.java b/app/src/main/java/acr/browser/lightning/search/SuggestionsAdapter.java index ccb4281..54c24b6 100644 --- a/app/src/main/java/acr/browser/lightning/search/SuggestionsAdapter.java +++ b/app/src/main/java/acr/browser/lightning/search/SuggestionsAdapter.java @@ -302,11 +302,11 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable { @NonNull private Single> getSuggestionsForQuery(@NonNull final String query) { if (mSuggestionChoice == PreferenceManager.Suggestion.SUGGESTION_GOOGLE) { - return SuggestionsManager.createGoogleQueryObservable(query, mApplication); + return SuggestionsManager.INSTANCE.createGoogleQueryObservable(query, mApplication); } else if (mSuggestionChoice == PreferenceManager.Suggestion.SUGGESTION_DUCK) { - return SuggestionsManager.createDuckQueryObservable(query, mApplication); + return SuggestionsManager.INSTANCE.createDuckQueryObservable(query, mApplication); } else if (mSuggestionChoice == PreferenceManager.Suggestion.SUGGESTION_BAIDU) { - return SuggestionsManager.createBaiduQueryObservable(query, mApplication); + return SuggestionsManager.INSTANCE.createBaiduQueryObservable(query, mApplication); } else { return Single.empty(); } diff --git a/app/src/main/java/acr/browser/lightning/search/SuggestionsManager.java b/app/src/main/java/acr/browser/lightning/search/SuggestionsManager.java deleted file mode 100644 index 90bbf6b..0000000 --- a/app/src/main/java/acr/browser/lightning/search/SuggestionsManager.java +++ /dev/null @@ -1,70 +0,0 @@ -package acr.browser.lightning.search; - -import android.app.Application; -import android.support.annotation.NonNull; - -import com.anthonycr.bonsai.Single; -import com.anthonycr.bonsai.SingleAction; -import com.anthonycr.bonsai.SingleSubscriber; - -import java.util.List; - -import acr.browser.lightning.database.HistoryItem; -import acr.browser.lightning.search.suggestions.BaiduSuggestionsModel; -import acr.browser.lightning.search.suggestions.DuckSuggestionsModel; -import acr.browser.lightning.search.suggestions.GoogleSuggestionsModel; - -class SuggestionsManager { - - private static volatile boolean sIsTaskExecuting; - - static boolean isRequestInProgress() { - return sIsTaskExecuting; - } - - @NonNull - static Single> createGoogleQueryObservable(@NonNull final String query, - @NonNull final Application application) { - return Single.create(new SingleAction>() { - @Override - public void onSubscribe(@NonNull final SingleSubscriber> subscriber) { - sIsTaskExecuting = true; - List results = new GoogleSuggestionsModel(application).fetchResults(query); - subscriber.onItem(results); - subscriber.onComplete(); - sIsTaskExecuting = false; - } - }); - } - - @NonNull - static Single> createBaiduQueryObservable(@NonNull final String query, - @NonNull final Application application) { - return Single.create(new SingleAction>() { - @Override - public void onSubscribe(@NonNull final SingleSubscriber> subscriber) { - sIsTaskExecuting = true; - List results = new BaiduSuggestionsModel(application).fetchResults(query); - subscriber.onItem(results); - subscriber.onComplete(); - sIsTaskExecuting = false; - } - }); - } - - @NonNull - static Single> createDuckQueryObservable(@NonNull final String query, - @NonNull final Application application) { - return Single.create(new SingleAction>() { - @Override - public void onSubscribe(@NonNull final SingleSubscriber> subscriber) { - sIsTaskExecuting = true; - List results = new DuckSuggestionsModel(application).fetchResults(query); - subscriber.onItem(results); - subscriber.onComplete(); - sIsTaskExecuting = false; - } - }); - } - -} diff --git a/app/src/main/java/acr/browser/lightning/search/SuggestionsManager.kt b/app/src/main/java/acr/browser/lightning/search/SuggestionsManager.kt new file mode 100644 index 0000000..3a8edff --- /dev/null +++ b/app/src/main/java/acr/browser/lightning/search/SuggestionsManager.kt @@ -0,0 +1,43 @@ +package acr.browser.lightning.search + +import acr.browser.lightning.database.HistoryItem +import acr.browser.lightning.search.suggestions.BaiduSuggestionsModel +import acr.browser.lightning.search.suggestions.DuckSuggestionsModel +import acr.browser.lightning.search.suggestions.GoogleSuggestionsModel +import android.app.Application +import com.anthonycr.bonsai.Single +import com.anthonycr.bonsai.SingleAction + +internal object SuggestionsManager { + + @JvmStatic + @Volatile var isRequestInProgress: Boolean = false + + fun createGoogleQueryObservable(query: String, application: Application) = + Single.create(SingleAction> { subscriber -> + isRequestInProgress = true + val results = GoogleSuggestionsModel(application).fetchResults(query) + subscriber.onItem(results) + subscriber.onComplete() + isRequestInProgress = false + }) + + fun createBaiduQueryObservable(query: String, application: Application) = + Single.create(SingleAction> { subscriber -> + isRequestInProgress = true + val results = BaiduSuggestionsModel(application).fetchResults(query) + subscriber.onItem(results) + subscriber.onComplete() + isRequestInProgress = false + }) + + fun createDuckQueryObservable(query: String, application: Application) = + Single.create(SingleAction> { subscriber -> + isRequestInProgress = true + val results = DuckSuggestionsModel(application).fetchResults(query) + subscriber.onItem(results) + subscriber.onComplete() + isRequestInProgress = false + }) + +} diff --git a/build.gradle b/build.gradle index 6e6a447..b262873 100644 --- a/build.gradle +++ b/build.gradle @@ -1,10 +1,12 @@ buildscript { + ext.kotlin_version = '1.1.3' repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.3.3' classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.6.3' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } From 7251bccfeab2c625c34b3e27600a55d2c1c84045 Mon Sep 17 00:00:00 2001 From: Mohit Sarveiya Date: Mon, 26 Jun 2017 22:01:08 -0400 Subject: [PATCH 48/56] Clean up code --- .../acr/browser/lightning/search/SuggestionsAdapter.java | 6 +++--- .../java/acr/browser/lightning/search/SuggestionsManager.kt | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/acr/browser/lightning/search/SuggestionsAdapter.java b/app/src/main/java/acr/browser/lightning/search/SuggestionsAdapter.java index 54c24b6..ccb4281 100644 --- a/app/src/main/java/acr/browser/lightning/search/SuggestionsAdapter.java +++ b/app/src/main/java/acr/browser/lightning/search/SuggestionsAdapter.java @@ -302,11 +302,11 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable { @NonNull private Single> getSuggestionsForQuery(@NonNull final String query) { if (mSuggestionChoice == PreferenceManager.Suggestion.SUGGESTION_GOOGLE) { - return SuggestionsManager.INSTANCE.createGoogleQueryObservable(query, mApplication); + return SuggestionsManager.createGoogleQueryObservable(query, mApplication); } else if (mSuggestionChoice == PreferenceManager.Suggestion.SUGGESTION_DUCK) { - return SuggestionsManager.INSTANCE.createDuckQueryObservable(query, mApplication); + return SuggestionsManager.createDuckQueryObservable(query, mApplication); } else if (mSuggestionChoice == PreferenceManager.Suggestion.SUGGESTION_BAIDU) { - return SuggestionsManager.INSTANCE.createBaiduQueryObservable(query, mApplication); + return SuggestionsManager.createBaiduQueryObservable(query, mApplication); } else { return Single.empty(); } diff --git a/app/src/main/java/acr/browser/lightning/search/SuggestionsManager.kt b/app/src/main/java/acr/browser/lightning/search/SuggestionsManager.kt index 3a8edff..b28414e 100644 --- a/app/src/main/java/acr/browser/lightning/search/SuggestionsManager.kt +++ b/app/src/main/java/acr/browser/lightning/search/SuggestionsManager.kt @@ -13,6 +13,7 @@ internal object SuggestionsManager { @JvmStatic @Volatile var isRequestInProgress: Boolean = false + @JvmStatic fun createGoogleQueryObservable(query: String, application: Application) = Single.create(SingleAction> { subscriber -> isRequestInProgress = true @@ -22,6 +23,7 @@ internal object SuggestionsManager { isRequestInProgress = false }) + @JvmStatic fun createBaiduQueryObservable(query: String, application: Application) = Single.create(SingleAction> { subscriber -> isRequestInProgress = true @@ -31,6 +33,7 @@ internal object SuggestionsManager { isRequestInProgress = false }) + @JvmStatic fun createDuckQueryObservable(query: String, application: Application) = Single.create(SingleAction> { subscriber -> isRequestInProgress = true From a6c401624c9b9e706c351b8a9db35d108bb6253c Mon Sep 17 00:00:00 2001 From: anthony restaino Date: Mon, 26 Jun 2017 22:40:41 -0400 Subject: [PATCH 49/56] Improving packaging structure --- app/src/main/AndroidManifest.xml | 10 +++---- .../lightning/{app => }/BrowserApp.java | 8 ++++-- .../{activity => }/IncognitoActivity.java | 4 +-- .../{activity => }/MainActivity.java | 4 +-- .../activity/AppCompatPreferenceActivity.java | 4 +-- .../lightning/{utils => adblock}/AdBlock.java | 4 ++- .../lightning/browser/BrowserPresenter.java | 3 +- .../lightning/browser/SearchBoxModel.java | 2 +- .../{activity => browser}/TabsManager.java | 4 +-- .../activity/BrowserActivity.java | 28 +++++++++++-------- .../activity/ThemableBrowserActivity.java | 7 +++-- .../bookmark}/BookmarkUiModel.java | 2 +- .../fragment/BookmarksFragment.java | 10 +++---- .../{ => browser}/fragment/TabsFragment.java | 10 +++---- .../fragment/anim/HorizontalItemAnimator.java | 2 +- .../fragment/anim/VerticalItemAnimator.java | 2 +- .../lightning/constant/BookmarkPage.java | 2 +- .../lightning/constant/DownloadsPage.java | 2 +- .../lightning/constant/HistoryPage.java | 2 +- .../browser/lightning/constant/StartPage.java | 2 +- .../lightning/controller/UIController.java | 2 +- .../lightning/{app => di}/AppComponent.java | 27 +++++++++--------- .../lightning/{app => di}/AppModule.java | 3 +- .../dialog/LightningDialogBuilder.java | 4 +-- .../lightning/download/DownloadHandler.java | 4 +-- .../download/LightningDownloadListener.java | 2 +- .../activity/ReadingActivity.java | 4 +-- .../search/SearchEngineProvider.java | 2 +- .../lightning/search/SuggestionsAdapter.java | 2 +- .../activity/SettingsActivity.java | 4 +-- .../activity/ThemableSettingsActivity.java | 5 ++-- .../fragment/AboutSettingsFragment.java | 2 +- .../fragment/AdvancedSettingsFragment.java | 2 +- .../fragment/BookmarkSettingsFragment.java | 10 +++---- .../fragment/DebugSettingsFragment.java | 4 +-- .../fragment/DisplaySettingsFragment.java | 2 +- .../fragment/GeneralSettingsFragment.java | 4 +-- .../fragment/LightningPreferenceFragment.java | 4 +-- .../fragment/PrivacySettingsFragment.java | 4 +-- .../browser/lightning/utils/ProxyUtils.java | 2 +- .../lightning/utils/StringBuilderUtils.java | 4 +-- .../acr/browser/lightning/utils/Utils.java | 2 +- .../lightning/view/LightningChromeClient.java | 2 +- .../browser/lightning/view/LightningView.java | 2 +- .../lightning/view/LightningWebClient.java | 4 +-- app/src/main/res/layout/activity_main.xml | 2 +- app/src/main/res/xml/preferences_headers.xml | 14 +++++----- 47 files changed, 122 insertions(+), 113 deletions(-) rename app/src/main/java/acr/browser/lightning/{app => }/BrowserApp.java (96%) rename app/src/main/java/acr/browser/lightning/{activity => }/IncognitoActivity.java (95%) rename app/src/main/java/acr/browser/lightning/{activity => }/MainActivity.java (96%) rename app/src/main/java/acr/browser/lightning/{utils => adblock}/AdBlock.java (98%) rename app/src/main/java/acr/browser/lightning/{activity => browser}/TabsManager.java (99%) rename app/src/main/java/acr/browser/lightning/{ => browser}/activity/BrowserActivity.java (98%) rename app/src/main/java/acr/browser/lightning/{ => browser}/activity/ThemableBrowserActivity.java (93%) rename app/src/main/java/acr/browser/lightning/{activity => browser/bookmark}/BookmarkUiModel.java (95%) rename app/src/main/java/acr/browser/lightning/{ => browser}/fragment/BookmarksFragment.java (98%) rename app/src/main/java/acr/browser/lightning/{ => browser}/fragment/TabsFragment.java (98%) rename app/src/main/java/acr/browser/lightning/{ => browser}/fragment/anim/HorizontalItemAnimator.java (99%) rename app/src/main/java/acr/browser/lightning/{ => browser}/fragment/anim/VerticalItemAnimator.java (99%) rename app/src/main/java/acr/browser/lightning/{app => di}/AppComponent.java (72%) rename app/src/main/java/acr/browser/lightning/{app => di}/AppModule.java (95%) rename app/src/main/java/acr/browser/lightning/{ => reading}/activity/ReadingActivity.java (99%) rename app/src/main/java/acr/browser/lightning/{ => settings}/activity/SettingsActivity.java (96%) rename app/src/main/java/acr/browser/lightning/{ => settings}/activity/ThemableSettingsActivity.java (92%) rename app/src/main/java/acr/browser/lightning/{ => settings}/fragment/AboutSettingsFragment.java (95%) rename app/src/main/java/acr/browser/lightning/{ => settings}/fragment/AdvancedSettingsFragment.java (99%) rename app/src/main/java/acr/browser/lightning/{ => settings}/fragment/BookmarkSettingsFragment.java (99%) rename app/src/main/java/acr/browser/lightning/{ => settings}/fragment/DebugSettingsFragment.java (95%) rename app/src/main/java/acr/browser/lightning/{ => settings}/fragment/DisplaySettingsFragment.java (99%) rename app/src/main/java/acr/browser/lightning/{ => settings}/fragment/GeneralSettingsFragment.java (99%) rename app/src/main/java/acr/browser/lightning/{ => settings}/fragment/LightningPreferenceFragment.java (86%) rename app/src/main/java/acr/browser/lightning/{ => settings}/fragment/PrivacySettingsFragment.java (99%) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f1a249f..ea99c1e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -25,7 +25,7 @@ android:required="false"/> @@ -133,7 +133,7 @@ diff --git a/app/src/main/java/acr/browser/lightning/app/BrowserApp.java b/app/src/main/java/acr/browser/lightning/BrowserApp.java similarity index 96% rename from app/src/main/java/acr/browser/lightning/app/BrowserApp.java rename to app/src/main/java/acr/browser/lightning/BrowserApp.java index 1bbc19a..7d5fdf9 100644 --- a/app/src/main/java/acr/browser/lightning/app/BrowserApp.java +++ b/app/src/main/java/acr/browser/lightning/BrowserApp.java @@ -1,4 +1,4 @@ -package acr.browser.lightning.app; +package acr.browser.lightning; import android.app.Activity; import android.app.Application; @@ -20,11 +20,13 @@ import java.util.List; import javax.inject.Inject; -import acr.browser.lightning.BuildConfig; import acr.browser.lightning.database.HistoryItem; import acr.browser.lightning.database.bookmark.BookmarkExporter; -import acr.browser.lightning.database.bookmark.legacy.LegacyBookmarkManager; import acr.browser.lightning.database.bookmark.BookmarkModel; +import acr.browser.lightning.database.bookmark.legacy.LegacyBookmarkManager; +import acr.browser.lightning.di.AppComponent; +import acr.browser.lightning.di.AppModule; +import acr.browser.lightning.di.DaggerAppComponent; import acr.browser.lightning.preference.PreferenceManager; import acr.browser.lightning.utils.FileUtils; import acr.browser.lightning.utils.MemoryLeakUtils; diff --git a/app/src/main/java/acr/browser/lightning/activity/IncognitoActivity.java b/app/src/main/java/acr/browser/lightning/IncognitoActivity.java similarity index 95% rename from app/src/main/java/acr/browser/lightning/activity/IncognitoActivity.java rename to app/src/main/java/acr/browser/lightning/IncognitoActivity.java index 9f085b5..ecdb908 100644 --- a/app/src/main/java/acr/browser/lightning/activity/IncognitoActivity.java +++ b/app/src/main/java/acr/browser/lightning/IncognitoActivity.java @@ -1,4 +1,4 @@ -package acr.browser.lightning.activity; +package acr.browser.lightning; import android.content.Intent; import android.os.Build; @@ -12,7 +12,7 @@ import com.anthonycr.bonsai.Completable; import com.anthonycr.bonsai.CompletableAction; import com.anthonycr.bonsai.CompletableSubscriber; -import acr.browser.lightning.R; +import acr.browser.lightning.browser.activity.BrowserActivity; @SuppressWarnings("deprecation") public class IncognitoActivity extends BrowserActivity { diff --git a/app/src/main/java/acr/browser/lightning/activity/MainActivity.java b/app/src/main/java/acr/browser/lightning/MainActivity.java similarity index 96% rename from app/src/main/java/acr/browser/lightning/activity/MainActivity.java rename to app/src/main/java/acr/browser/lightning/MainActivity.java index 30782b0..298c362 100644 --- a/app/src/main/java/acr/browser/lightning/activity/MainActivity.java +++ b/app/src/main/java/acr/browser/lightning/MainActivity.java @@ -1,4 +1,4 @@ -package acr.browser.lightning.activity; +package acr.browser.lightning; import android.content.Intent; import android.os.Build; @@ -13,7 +13,7 @@ import com.anthonycr.bonsai.Completable; import com.anthonycr.bonsai.CompletableAction; import com.anthonycr.bonsai.CompletableSubscriber; -import acr.browser.lightning.R; +import acr.browser.lightning.browser.activity.BrowserActivity; @SuppressWarnings("deprecation") public class MainActivity extends BrowserActivity { diff --git a/app/src/main/java/acr/browser/lightning/activity/AppCompatPreferenceActivity.java b/app/src/main/java/acr/browser/lightning/activity/AppCompatPreferenceActivity.java index 14f70b1..9110e6e 100644 --- a/app/src/main/java/acr/browser/lightning/activity/AppCompatPreferenceActivity.java +++ b/app/src/main/java/acr/browser/lightning/activity/AppCompatPreferenceActivity.java @@ -40,11 +40,11 @@ public abstract class AppCompatPreferenceActivity extends PreferenceActivity { getDelegate().onPostCreate(savedInstanceState); } - ActionBar getSupportActionBar() { + protected final ActionBar getSupportActionBar() { return getDelegate().getSupportActionBar(); } - void setSupportActionBar(@Nullable Toolbar toolbar) { + protected final void setSupportActionBar(@Nullable Toolbar toolbar) { getDelegate().setSupportActionBar(toolbar); } diff --git a/app/src/main/java/acr/browser/lightning/utils/AdBlock.java b/app/src/main/java/acr/browser/lightning/adblock/AdBlock.java similarity index 98% rename from app/src/main/java/acr/browser/lightning/utils/AdBlock.java rename to app/src/main/java/acr/browser/lightning/adblock/AdBlock.java index 0fd6fc0..6cd948f 100644 --- a/app/src/main/java/acr/browser/lightning/utils/AdBlock.java +++ b/app/src/main/java/acr/browser/lightning/adblock/AdBlock.java @@ -1,4 +1,4 @@ -package acr.browser.lightning.utils; +package acr.browser.lightning.adblock; import android.app.Application; import android.content.res.AssetManager; @@ -24,6 +24,8 @@ import javax.inject.Singleton; import acr.browser.lightning.BuildConfig; import acr.browser.lightning.preference.PreferenceManager; +import acr.browser.lightning.utils.StringBuilderUtils; +import acr.browser.lightning.utils.Utils; @Singleton public class AdBlock { diff --git a/app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java b/app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java index c53258c..a92b6a4 100644 --- a/app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java +++ b/app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java @@ -16,8 +16,7 @@ import javax.inject.Inject; import acr.browser.lightning.BuildConfig; import acr.browser.lightning.R; -import acr.browser.lightning.activity.TabsManager; -import acr.browser.lightning.app.BrowserApp; +import acr.browser.lightning.BrowserApp; import acr.browser.lightning.constant.BookmarkPage; import acr.browser.lightning.constant.Constants; import acr.browser.lightning.constant.StartPage; diff --git a/app/src/main/java/acr/browser/lightning/browser/SearchBoxModel.java b/app/src/main/java/acr/browser/lightning/browser/SearchBoxModel.java index 8d5a179..4e3e073 100644 --- a/app/src/main/java/acr/browser/lightning/browser/SearchBoxModel.java +++ b/app/src/main/java/acr/browser/lightning/browser/SearchBoxModel.java @@ -8,7 +8,7 @@ import android.text.TextUtils; import javax.inject.Inject; import acr.browser.lightning.R; -import acr.browser.lightning.app.BrowserApp; +import acr.browser.lightning.BrowserApp; import acr.browser.lightning.preference.PreferenceManager; import acr.browser.lightning.utils.UrlUtils; import acr.browser.lightning.utils.Utils; diff --git a/app/src/main/java/acr/browser/lightning/activity/TabsManager.java b/app/src/main/java/acr/browser/lightning/browser/TabsManager.java similarity index 99% rename from app/src/main/java/acr/browser/lightning/activity/TabsManager.java rename to app/src/main/java/acr/browser/lightning/browser/TabsManager.java index 6e3559d..a7098a4 100644 --- a/app/src/main/java/acr/browser/lightning/activity/TabsManager.java +++ b/app/src/main/java/acr/browser/lightning/browser/TabsManager.java @@ -1,4 +1,4 @@ -package acr.browser.lightning.activity; +package acr.browser.lightning.browser; import android.app.Activity; import android.app.Application; @@ -31,7 +31,7 @@ import java.util.List; import javax.inject.Inject; import acr.browser.lightning.R; -import acr.browser.lightning.app.BrowserApp; +import acr.browser.lightning.BrowserApp; import acr.browser.lightning.constant.BookmarkPage; import acr.browser.lightning.constant.DownloadsPage; import acr.browser.lightning.constant.HistoryPage; diff --git a/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java b/app/src/main/java/acr/browser/lightning/browser/activity/BrowserActivity.java similarity index 98% rename from app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java rename to app/src/main/java/acr/browser/lightning/browser/activity/BrowserActivity.java index 454478d..81b7a1f 100644 --- a/app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java +++ b/app/src/main/java/acr/browser/lightning/browser/activity/BrowserActivity.java @@ -2,7 +2,7 @@ * Copyright 2015 Anthony Restaino */ -package acr.browser.lightning.activity; +package acr.browser.lightning.browser.activity; import android.app.Activity; import android.app.Dialog; @@ -90,12 +90,15 @@ import java.io.IOException; import javax.inject.Inject; import acr.browser.lightning.R; -import acr.browser.lightning.app.BrowserApp; +import acr.browser.lightning.reading.activity.ReadingActivity; import acr.browser.lightning.browser.BookmarksView; import acr.browser.lightning.browser.BrowserPresenter; import acr.browser.lightning.browser.BrowserView; +import acr.browser.lightning.IncognitoActivity; import acr.browser.lightning.browser.SearchBoxModel; +import acr.browser.lightning.browser.TabsManager; import acr.browser.lightning.browser.TabsView; +import acr.browser.lightning.BrowserApp; import acr.browser.lightning.constant.Constants; import acr.browser.lightning.constant.DownloadsPage; import acr.browser.lightning.constant.HistoryPage; @@ -105,13 +108,14 @@ import acr.browser.lightning.database.bookmark.BookmarkModel; import acr.browser.lightning.database.history.HistoryModel; import acr.browser.lightning.dialog.BrowserDialog; import acr.browser.lightning.dialog.LightningDialogBuilder; -import acr.browser.lightning.fragment.BookmarksFragment; -import acr.browser.lightning.fragment.TabsFragment; +import acr.browser.lightning.browser.fragment.BookmarksFragment; +import acr.browser.lightning.browser.fragment.TabsFragment; import acr.browser.lightning.interpolator.BezierDecelerateInterpolator; import acr.browser.lightning.receiver.NetworkReceiver; import acr.browser.lightning.search.SearchEngineProvider; import acr.browser.lightning.search.SuggestionsAdapter; import acr.browser.lightning.search.engine.BaseSearchEngine; +import acr.browser.lightning.settings.activity.SettingsActivity; import acr.browser.lightning.utils.DrawableUtils; import acr.browser.lightning.utils.IntentUtils; import acr.browser.lightning.utils.Preconditions; @@ -224,7 +228,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements public abstract void updateHistory(@Nullable final String title, @NonNull final String url); @NonNull - abstract Completable updateCookiePreference(); + protected abstract Completable updateCookiePreference(); @Override protected void onCreate(Bundle savedInstanceState) { @@ -451,11 +455,11 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements * @return true if the panic trigger sent * the intent, false otherwise. */ - static boolean isPanicTrigger(@Nullable Intent intent) { + protected static boolean isPanicTrigger(@Nullable Intent intent) { return intent != null && INTENT_PANIC_TRIGGER.equals(intent.getAction()); } - void panicClean() { + protected void panicClean() { Log.d(TAG, "Closing browser"); mTabsManager.newTab(this, "", false); mTabsManager.switchToTab(0); @@ -1208,7 +1212,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements } } - void handleNewIntent(Intent intent) { + protected void handleNewIntent(Intent intent) { mPresenter.onNewIntent(intent); } @@ -1232,7 +1236,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements return mPresenter.newTab(url, show); } - void performExitCleanUp() { + protected void performExitCleanUp() { final LightningView currentTab = mTabsManager.getCurrentTab(); if (mPreferences.getClearCacheExit() && currentTab != null && !isIncognito()) { WebUtils.clearCache(currentTab.getWebView()); @@ -1358,7 +1362,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements } } - void saveOpenTabs() { + protected void saveOpenTabs() { if (mPreferences.getRestoreLostTabsEnabled()) { mTabsManager.saveState(); } @@ -1548,7 +1552,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements mProgressBar.setProgress(n); } - void addItemToHistory(@Nullable final String title, @NonNull final String url) { + protected void addItemToHistory(@Nullable final String title, @NonNull final String url) { if (UrlUtils.isSpecialUrl(url)) { return; } @@ -1665,7 +1669,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements * @param runnable an optional runnable to run after * the drawers are closed. */ - void closeDrawers(@Nullable final Runnable runnable) { + protected final void closeDrawers(@Nullable final Runnable runnable) { if (!mDrawerLayout.isDrawerOpen(mDrawerLeft) && !mDrawerLayout.isDrawerOpen(mDrawerRight)) { if (runnable != null) { runnable.run(); diff --git a/app/src/main/java/acr/browser/lightning/activity/ThemableBrowserActivity.java b/app/src/main/java/acr/browser/lightning/browser/activity/ThemableBrowserActivity.java similarity index 93% rename from app/src/main/java/acr/browser/lightning/activity/ThemableBrowserActivity.java rename to app/src/main/java/acr/browser/lightning/browser/activity/ThemableBrowserActivity.java index 3a29986..0084882 100644 --- a/app/src/main/java/acr/browser/lightning/activity/ThemableBrowserActivity.java +++ b/app/src/main/java/acr/browser/lightning/browser/activity/ThemableBrowserActivity.java @@ -1,4 +1,4 @@ -package acr.browser.lightning.activity; +package acr.browser.lightning.browser.activity; import android.content.Intent; import android.content.res.Configuration; @@ -10,13 +10,14 @@ import android.support.v7.app.AppCompatActivity; import javax.inject.Inject; import acr.browser.lightning.R; -import acr.browser.lightning.app.BrowserApp; +import acr.browser.lightning.BrowserApp; import acr.browser.lightning.preference.PreferenceManager; import acr.browser.lightning.utils.ThemeUtils; public abstract class ThemableBrowserActivity extends AppCompatActivity { - @Inject PreferenceManager mPreferences; + // TODO: 6/26/17 get rid fo protected reference + @Inject protected PreferenceManager mPreferences; private int mTheme; private boolean mShowTabsInDrawer; diff --git a/app/src/main/java/acr/browser/lightning/activity/BookmarkUiModel.java b/app/src/main/java/acr/browser/lightning/browser/bookmark/BookmarkUiModel.java similarity index 95% rename from app/src/main/java/acr/browser/lightning/activity/BookmarkUiModel.java rename to app/src/main/java/acr/browser/lightning/browser/bookmark/BookmarkUiModel.java index 457a984..0d42c0b 100644 --- a/app/src/main/java/acr/browser/lightning/activity/BookmarkUiModel.java +++ b/app/src/main/java/acr/browser/lightning/browser/bookmark/BookmarkUiModel.java @@ -1,4 +1,4 @@ -package acr.browser.lightning.activity; +package acr.browser.lightning.browser.bookmark; import android.support.annotation.Nullable; diff --git a/app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java b/app/src/main/java/acr/browser/lightning/browser/fragment/BookmarksFragment.java similarity index 98% rename from app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java rename to app/src/main/java/acr/browser/lightning/browser/fragment/BookmarksFragment.java index f998eaa..ebe0c34 100644 --- a/app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java +++ b/app/src/main/java/acr/browser/lightning/browser/fragment/BookmarksFragment.java @@ -1,4 +1,4 @@ -package acr.browser.lightning.fragment; +package acr.browser.lightning.browser.fragment; import android.app.Activity; import android.content.Context; @@ -34,11 +34,11 @@ import java.util.concurrent.ConcurrentHashMap; import javax.inject.Inject; import acr.browser.lightning.R; -import acr.browser.lightning.activity.BookmarkUiModel; -import acr.browser.lightning.activity.ReadingActivity; -import acr.browser.lightning.activity.TabsManager; +import acr.browser.lightning.browser.bookmark.BookmarkUiModel; +import acr.browser.lightning.reading.activity.ReadingActivity; +import acr.browser.lightning.browser.TabsManager; import acr.browser.lightning.animation.AnimationUtils; -import acr.browser.lightning.app.BrowserApp; +import acr.browser.lightning.BrowserApp; import acr.browser.lightning.browser.BookmarksView; import acr.browser.lightning.constant.Constants; import acr.browser.lightning.controller.UIController; diff --git a/app/src/main/java/acr/browser/lightning/fragment/TabsFragment.java b/app/src/main/java/acr/browser/lightning/browser/fragment/TabsFragment.java similarity index 98% rename from app/src/main/java/acr/browser/lightning/fragment/TabsFragment.java rename to app/src/main/java/acr/browser/lightning/browser/fragment/TabsFragment.java index 0fed33a..beed6ca 100644 --- a/app/src/main/java/acr/browser/lightning/fragment/TabsFragment.java +++ b/app/src/main/java/acr/browser/lightning/browser/fragment/TabsFragment.java @@ -1,4 +1,4 @@ -package acr.browser.lightning.fragment; +package acr.browser.lightning.browser.fragment; import android.app.Activity; import android.content.Context; @@ -34,12 +34,12 @@ import android.widget.TextView; import javax.inject.Inject; import acr.browser.lightning.R; -import acr.browser.lightning.activity.TabsManager; -import acr.browser.lightning.app.BrowserApp; +import acr.browser.lightning.browser.TabsManager; +import acr.browser.lightning.BrowserApp; import acr.browser.lightning.browser.TabsView; import acr.browser.lightning.controller.UIController; -import acr.browser.lightning.fragment.anim.HorizontalItemAnimator; -import acr.browser.lightning.fragment.anim.VerticalItemAnimator; +import acr.browser.lightning.browser.fragment.anim.HorizontalItemAnimator; +import acr.browser.lightning.browser.fragment.anim.VerticalItemAnimator; import acr.browser.lightning.preference.PreferenceManager; import acr.browser.lightning.utils.DrawableUtils; import acr.browser.lightning.utils.ThemeUtils; diff --git a/app/src/main/java/acr/browser/lightning/fragment/anim/HorizontalItemAnimator.java b/app/src/main/java/acr/browser/lightning/browser/fragment/anim/HorizontalItemAnimator.java similarity index 99% rename from app/src/main/java/acr/browser/lightning/fragment/anim/HorizontalItemAnimator.java rename to app/src/main/java/acr/browser/lightning/browser/fragment/anim/HorizontalItemAnimator.java index 732cf96..dce2886 100644 --- a/app/src/main/java/acr/browser/lightning/fragment/anim/HorizontalItemAnimator.java +++ b/app/src/main/java/acr/browser/lightning/browser/fragment/anim/HorizontalItemAnimator.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package acr.browser.lightning.fragment.anim; +package acr.browser.lightning.browser.fragment.anim; import android.animation.TimeInterpolator; import android.animation.ValueAnimator; diff --git a/app/src/main/java/acr/browser/lightning/fragment/anim/VerticalItemAnimator.java b/app/src/main/java/acr/browser/lightning/browser/fragment/anim/VerticalItemAnimator.java similarity index 99% rename from app/src/main/java/acr/browser/lightning/fragment/anim/VerticalItemAnimator.java rename to app/src/main/java/acr/browser/lightning/browser/fragment/anim/VerticalItemAnimator.java index 4a2f5ee..ea18b33 100644 --- a/app/src/main/java/acr/browser/lightning/fragment/anim/VerticalItemAnimator.java +++ b/app/src/main/java/acr/browser/lightning/browser/fragment/anim/VerticalItemAnimator.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package acr.browser.lightning.fragment.anim; +package acr.browser.lightning.browser.fragment.anim; import android.animation.TimeInterpolator; import android.animation.ValueAnimator; diff --git a/app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java b/app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java index 4742801..0f1707f 100644 --- a/app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java +++ b/app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java @@ -26,7 +26,7 @@ import java.util.List; import javax.inject.Inject; import acr.browser.lightning.R; -import acr.browser.lightning.app.BrowserApp; +import acr.browser.lightning.BrowserApp; import acr.browser.lightning.database.HistoryItem; import acr.browser.lightning.database.bookmark.BookmarkModel; import acr.browser.lightning.favicon.FaviconModel; diff --git a/app/src/main/java/acr/browser/lightning/constant/DownloadsPage.java b/app/src/main/java/acr/browser/lightning/constant/DownloadsPage.java index 119c676..4b621bb 100644 --- a/app/src/main/java/acr/browser/lightning/constant/DownloadsPage.java +++ b/app/src/main/java/acr/browser/lightning/constant/DownloadsPage.java @@ -21,7 +21,7 @@ import java.util.List; import javax.inject.Inject; import acr.browser.lightning.R; -import acr.browser.lightning.app.BrowserApp; +import acr.browser.lightning.BrowserApp; import acr.browser.lightning.database.downloads.DownloadItem; import acr.browser.lightning.database.downloads.DownloadsModel; import acr.browser.lightning.preference.PreferenceManager; diff --git a/app/src/main/java/acr/browser/lightning/constant/HistoryPage.java b/app/src/main/java/acr/browser/lightning/constant/HistoryPage.java index e42d83a..cd2cd3e 100644 --- a/app/src/main/java/acr/browser/lightning/constant/HistoryPage.java +++ b/app/src/main/java/acr/browser/lightning/constant/HistoryPage.java @@ -25,7 +25,7 @@ import java.util.List; import javax.inject.Inject; import acr.browser.lightning.R; -import acr.browser.lightning.app.BrowserApp; +import acr.browser.lightning.BrowserApp; import acr.browser.lightning.database.HistoryItem; import acr.browser.lightning.database.history.HistoryModel; import acr.browser.lightning.utils.Preconditions; diff --git a/app/src/main/java/acr/browser/lightning/constant/StartPage.java b/app/src/main/java/acr/browser/lightning/constant/StartPage.java index 873481e..1ea3d26 100644 --- a/app/src/main/java/acr/browser/lightning/constant/StartPage.java +++ b/app/src/main/java/acr/browser/lightning/constant/StartPage.java @@ -17,7 +17,7 @@ import java.io.IOException; import javax.inject.Inject; import acr.browser.lightning.R; -import acr.browser.lightning.app.BrowserApp; +import acr.browser.lightning.BrowserApp; import acr.browser.lightning.search.SearchEngineProvider; import acr.browser.lightning.search.engine.BaseSearchEngine; import acr.browser.lightning.utils.Utils; diff --git a/app/src/main/java/acr/browser/lightning/controller/UIController.java b/app/src/main/java/acr/browser/lightning/controller/UIController.java index c708585..93acd6e 100644 --- a/app/src/main/java/acr/browser/lightning/controller/UIController.java +++ b/app/src/main/java/acr/browser/lightning/controller/UIController.java @@ -14,7 +14,7 @@ import android.view.View; import android.webkit.ValueCallback; import android.webkit.WebChromeClient.CustomViewCallback; -import acr.browser.lightning.activity.TabsManager; +import acr.browser.lightning.browser.TabsManager; import acr.browser.lightning.database.HistoryItem; import acr.browser.lightning.dialog.LightningDialogBuilder; import acr.browser.lightning.view.LightningView; diff --git a/app/src/main/java/acr/browser/lightning/app/AppComponent.java b/app/src/main/java/acr/browser/lightning/di/AppComponent.java similarity index 72% rename from app/src/main/java/acr/browser/lightning/app/AppComponent.java rename to app/src/main/java/acr/browser/lightning/di/AppComponent.java index 17f7c12..635b3f9 100644 --- a/app/src/main/java/acr/browser/lightning/app/AppComponent.java +++ b/app/src/main/java/acr/browser/lightning/di/AppComponent.java @@ -1,12 +1,13 @@ -package acr.browser.lightning.app; +package acr.browser.lightning.di; import javax.inject.Singleton; -import acr.browser.lightning.activity.BrowserActivity; -import acr.browser.lightning.activity.ReadingActivity; -import acr.browser.lightning.activity.TabsManager; -import acr.browser.lightning.activity.ThemableBrowserActivity; -import acr.browser.lightning.activity.ThemableSettingsActivity; +import acr.browser.lightning.browser.activity.BrowserActivity; +import acr.browser.lightning.reading.activity.ReadingActivity; +import acr.browser.lightning.browser.TabsManager; +import acr.browser.lightning.browser.activity.ThemableBrowserActivity; +import acr.browser.lightning.settings.activity.ThemableSettingsActivity; +import acr.browser.lightning.BrowserApp; import acr.browser.lightning.browser.BrowserPresenter; import acr.browser.lightning.browser.SearchBoxModel; import acr.browser.lightning.constant.BookmarkPage; @@ -16,13 +17,13 @@ import acr.browser.lightning.constant.StartPage; import acr.browser.lightning.dialog.LightningDialogBuilder; import acr.browser.lightning.download.DownloadHandler; import acr.browser.lightning.download.LightningDownloadListener; -import acr.browser.lightning.fragment.BookmarkSettingsFragment; -import acr.browser.lightning.fragment.BookmarksFragment; -import acr.browser.lightning.fragment.DebugSettingsFragment; -import acr.browser.lightning.fragment.GeneralSettingsFragment; -import acr.browser.lightning.fragment.LightningPreferenceFragment; -import acr.browser.lightning.fragment.PrivacySettingsFragment; -import acr.browser.lightning.fragment.TabsFragment; +import acr.browser.lightning.settings.fragment.BookmarkSettingsFragment; +import acr.browser.lightning.browser.fragment.BookmarksFragment; +import acr.browser.lightning.settings.fragment.DebugSettingsFragment; +import acr.browser.lightning.settings.fragment.GeneralSettingsFragment; +import acr.browser.lightning.settings.fragment.LightningPreferenceFragment; +import acr.browser.lightning.settings.fragment.PrivacySettingsFragment; +import acr.browser.lightning.browser.fragment.TabsFragment; import acr.browser.lightning.search.SearchEngineProvider; import acr.browser.lightning.search.SuggestionsAdapter; import acr.browser.lightning.utils.ProxyUtils; diff --git a/app/src/main/java/acr/browser/lightning/app/AppModule.java b/app/src/main/java/acr/browser/lightning/di/AppModule.java similarity index 95% rename from app/src/main/java/acr/browser/lightning/app/AppModule.java rename to app/src/main/java/acr/browser/lightning/di/AppModule.java index 32fbf0c..f0ec050 100644 --- a/app/src/main/java/acr/browser/lightning/app/AppModule.java +++ b/app/src/main/java/acr/browser/lightning/di/AppModule.java @@ -1,4 +1,4 @@ -package acr.browser.lightning.app; +package acr.browser.lightning.di; import android.app.Application; import android.content.Context; @@ -8,6 +8,7 @@ import net.i2p.android.ui.I2PAndroidHelper; import javax.inject.Singleton; +import acr.browser.lightning.BrowserApp; import acr.browser.lightning.database.bookmark.BookmarkDatabase; import acr.browser.lightning.database.bookmark.BookmarkModel; import acr.browser.lightning.database.downloads.DownloadsDatabase; diff --git a/app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java b/app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java index 600d65a..d925a6f 100644 --- a/app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java +++ b/app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java @@ -22,8 +22,8 @@ import java.util.List; import javax.inject.Inject; import acr.browser.lightning.R; -import acr.browser.lightning.activity.MainActivity; -import acr.browser.lightning.app.BrowserApp; +import acr.browser.lightning.MainActivity; +import acr.browser.lightning.BrowserApp; import acr.browser.lightning.constant.BookmarkPage; import acr.browser.lightning.constant.Constants; import acr.browser.lightning.controller.UIController; diff --git a/app/src/main/java/acr/browser/lightning/download/DownloadHandler.java b/app/src/main/java/acr/browser/lightning/download/DownloadHandler.java index fc53bc6..dd315ae 100644 --- a/app/src/main/java/acr/browser/lightning/download/DownloadHandler.java +++ b/app/src/main/java/acr/browser/lightning/download/DownloadHandler.java @@ -32,8 +32,8 @@ import javax.inject.Inject; import acr.browser.lightning.BuildConfig; import acr.browser.lightning.R; -import acr.browser.lightning.activity.MainActivity; -import acr.browser.lightning.app.BrowserApp; +import acr.browser.lightning.MainActivity; +import acr.browser.lightning.BrowserApp; import acr.browser.lightning.constant.Constants; import acr.browser.lightning.controller.UIController; import acr.browser.lightning.database.downloads.DownloadItem; diff --git a/app/src/main/java/acr/browser/lightning/download/LightningDownloadListener.java b/app/src/main/java/acr/browser/lightning/download/LightningDownloadListener.java index eda4ddd..227da44 100644 --- a/app/src/main/java/acr/browser/lightning/download/LightningDownloadListener.java +++ b/app/src/main/java/acr/browser/lightning/download/LightningDownloadListener.java @@ -14,7 +14,7 @@ import android.webkit.DownloadListener; import android.webkit.URLUtil; import acr.browser.lightning.R; -import acr.browser.lightning.app.BrowserApp; +import acr.browser.lightning.BrowserApp; import acr.browser.lightning.database.downloads.DownloadsModel; import acr.browser.lightning.dialog.BrowserDialog; import acr.browser.lightning.preference.PreferenceManager; diff --git a/app/src/main/java/acr/browser/lightning/activity/ReadingActivity.java b/app/src/main/java/acr/browser/lightning/reading/activity/ReadingActivity.java similarity index 99% rename from app/src/main/java/acr/browser/lightning/activity/ReadingActivity.java rename to app/src/main/java/acr/browser/lightning/reading/activity/ReadingActivity.java index 705597d..fd351ac 100644 --- a/app/src/main/java/acr/browser/lightning/activity/ReadingActivity.java +++ b/app/src/main/java/acr/browser/lightning/reading/activity/ReadingActivity.java @@ -1,4 +1,4 @@ -package acr.browser.lightning.activity; +package acr.browser.lightning.reading.activity; import android.animation.ObjectAnimator; import android.app.Dialog; @@ -26,7 +26,7 @@ import android.widget.TextView; import javax.inject.Inject; import acr.browser.lightning.R; -import acr.browser.lightning.app.BrowserApp; +import acr.browser.lightning.BrowserApp; import acr.browser.lightning.constant.Constants; import acr.browser.lightning.dialog.BrowserDialog; import acr.browser.lightning.preference.PreferenceManager; diff --git a/app/src/main/java/acr/browser/lightning/search/SearchEngineProvider.java b/app/src/main/java/acr/browser/lightning/search/SearchEngineProvider.java index bf9dd39..8889d62 100644 --- a/app/src/main/java/acr/browser/lightning/search/SearchEngineProvider.java +++ b/app/src/main/java/acr/browser/lightning/search/SearchEngineProvider.java @@ -7,7 +7,7 @@ import java.util.List; import javax.inject.Inject; -import acr.browser.lightning.app.BrowserApp; +import acr.browser.lightning.BrowserApp; import acr.browser.lightning.preference.PreferenceManager; import acr.browser.lightning.search.engine.AskSearch; import acr.browser.lightning.search.engine.BaiduSearch; diff --git a/app/src/main/java/acr/browser/lightning/search/SuggestionsAdapter.java b/app/src/main/java/acr/browser/lightning/search/SuggestionsAdapter.java index ccb4281..314639c 100644 --- a/app/src/main/java/acr/browser/lightning/search/SuggestionsAdapter.java +++ b/app/src/main/java/acr/browser/lightning/search/SuggestionsAdapter.java @@ -37,7 +37,7 @@ import java.util.Locale; import javax.inject.Inject; import acr.browser.lightning.R; -import acr.browser.lightning.app.BrowserApp; +import acr.browser.lightning.BrowserApp; import acr.browser.lightning.database.HistoryItem; import acr.browser.lightning.database.bookmark.BookmarkModel; import acr.browser.lightning.database.history.HistoryModel; diff --git a/app/src/main/java/acr/browser/lightning/activity/SettingsActivity.java b/app/src/main/java/acr/browser/lightning/settings/activity/SettingsActivity.java similarity index 96% rename from app/src/main/java/acr/browser/lightning/activity/SettingsActivity.java rename to app/src/main/java/acr/browser/lightning/settings/activity/SettingsActivity.java index 9299cc2..8671c5b 100644 --- a/app/src/main/java/acr/browser/lightning/activity/SettingsActivity.java +++ b/app/src/main/java/acr/browser/lightning/settings/activity/SettingsActivity.java @@ -1,7 +1,7 @@ /* * Copyright 2014 A.C.R. Development */ -package acr.browser.lightning.activity; +package acr.browser.lightning.settings.activity; import android.os.Build; import android.os.Bundle; @@ -19,7 +19,7 @@ import java.util.Iterator; import java.util.List; import acr.browser.lightning.R; -import acr.browser.lightning.app.BrowserApp; +import acr.browser.lightning.BrowserApp; public class SettingsActivity extends ThemableSettingsActivity { diff --git a/app/src/main/java/acr/browser/lightning/activity/ThemableSettingsActivity.java b/app/src/main/java/acr/browser/lightning/settings/activity/ThemableSettingsActivity.java similarity index 92% rename from app/src/main/java/acr/browser/lightning/activity/ThemableSettingsActivity.java rename to app/src/main/java/acr/browser/lightning/settings/activity/ThemableSettingsActivity.java index ebc2c1e..008ce7f 100644 --- a/app/src/main/java/acr/browser/lightning/activity/ThemableSettingsActivity.java +++ b/app/src/main/java/acr/browser/lightning/settings/activity/ThemableSettingsActivity.java @@ -1,4 +1,4 @@ -package acr.browser.lightning.activity; +package acr.browser.lightning.settings.activity; import android.graphics.Color; import android.graphics.drawable.ColorDrawable; @@ -8,7 +8,8 @@ import android.os.Bundle; import javax.inject.Inject; import acr.browser.lightning.R; -import acr.browser.lightning.app.BrowserApp; +import acr.browser.lightning.activity.AppCompatPreferenceActivity; +import acr.browser.lightning.BrowserApp; import acr.browser.lightning.preference.PreferenceManager; import acr.browser.lightning.utils.ThemeUtils; diff --git a/app/src/main/java/acr/browser/lightning/fragment/AboutSettingsFragment.java b/app/src/main/java/acr/browser/lightning/settings/fragment/AboutSettingsFragment.java similarity index 95% rename from app/src/main/java/acr/browser/lightning/fragment/AboutSettingsFragment.java rename to app/src/main/java/acr/browser/lightning/settings/fragment/AboutSettingsFragment.java index ce4c4be..2cf9bf1 100644 --- a/app/src/main/java/acr/browser/lightning/fragment/AboutSettingsFragment.java +++ b/app/src/main/java/acr/browser/lightning/settings/fragment/AboutSettingsFragment.java @@ -1,7 +1,7 @@ /* * Copyright 2014 A.C.R. Development */ -package acr.browser.lightning.fragment; +package acr.browser.lightning.settings.fragment; import android.app.Activity; import android.content.pm.PackageInfo; diff --git a/app/src/main/java/acr/browser/lightning/fragment/AdvancedSettingsFragment.java b/app/src/main/java/acr/browser/lightning/settings/fragment/AdvancedSettingsFragment.java similarity index 99% rename from app/src/main/java/acr/browser/lightning/fragment/AdvancedSettingsFragment.java rename to app/src/main/java/acr/browser/lightning/settings/fragment/AdvancedSettingsFragment.java index ba5d7da..ca89161 100644 --- a/app/src/main/java/acr/browser/lightning/fragment/AdvancedSettingsFragment.java +++ b/app/src/main/java/acr/browser/lightning/settings/fragment/AdvancedSettingsFragment.java @@ -1,7 +1,7 @@ /* * Copyright 2014 A.C.R. Development */ -package acr.browser.lightning.fragment; +package acr.browser.lightning.settings.fragment; import android.app.Activity; import android.app.Dialog; diff --git a/app/src/main/java/acr/browser/lightning/fragment/BookmarkSettingsFragment.java b/app/src/main/java/acr/browser/lightning/settings/fragment/BookmarkSettingsFragment.java similarity index 99% rename from app/src/main/java/acr/browser/lightning/fragment/BookmarkSettingsFragment.java rename to app/src/main/java/acr/browser/lightning/settings/fragment/BookmarkSettingsFragment.java index 28e755e..9a2de5a 100644 --- a/app/src/main/java/acr/browser/lightning/fragment/BookmarkSettingsFragment.java +++ b/app/src/main/java/acr/browser/lightning/settings/fragment/BookmarkSettingsFragment.java @@ -1,7 +1,7 @@ /* * Copyright 2014 A.C.R. Development */ -package acr.browser.lightning.fragment; +package acr.browser.lightning.settings.fragment; import android.Manifest; import android.app.Activity; @@ -23,6 +23,7 @@ import android.util.Log; import android.widget.ArrayAdapter; import com.anthonycr.bonsai.CompletableOnSubscribe; +import com.anthonycr.bonsai.Schedulers; import com.anthonycr.bonsai.SingleOnSubscribe; import com.anthonycr.bonsai.Subscription; import com.anthonycr.grant.PermissionsManager; @@ -38,14 +39,11 @@ import java.util.List; import javax.inject.Inject; import acr.browser.lightning.R; -import acr.browser.lightning.app.BrowserApp; +import acr.browser.lightning.BrowserApp; +import acr.browser.lightning.database.HistoryItem; import acr.browser.lightning.database.bookmark.BookmarkExporter; import acr.browser.lightning.database.bookmark.BookmarkLocalSync; import acr.browser.lightning.database.bookmark.BookmarkLocalSync.Source; -import acr.browser.lightning.database.HistoryItem; - -import com.anthonycr.bonsai.Schedulers; - import acr.browser.lightning.database.bookmark.BookmarkModel; import acr.browser.lightning.dialog.BrowserDialog; import acr.browser.lightning.utils.Preconditions; diff --git a/app/src/main/java/acr/browser/lightning/fragment/DebugSettingsFragment.java b/app/src/main/java/acr/browser/lightning/settings/fragment/DebugSettingsFragment.java similarity index 95% rename from app/src/main/java/acr/browser/lightning/fragment/DebugSettingsFragment.java rename to app/src/main/java/acr/browser/lightning/settings/fragment/DebugSettingsFragment.java index dba40b7..be6109a 100644 --- a/app/src/main/java/acr/browser/lightning/fragment/DebugSettingsFragment.java +++ b/app/src/main/java/acr/browser/lightning/settings/fragment/DebugSettingsFragment.java @@ -1,4 +1,4 @@ -package acr.browser.lightning.fragment; +package acr.browser.lightning.settings.fragment; import android.app.Activity; import android.os.Bundle; @@ -10,7 +10,7 @@ import android.support.annotation.NonNull; import javax.inject.Inject; import acr.browser.lightning.R; -import acr.browser.lightning.app.BrowserApp; +import acr.browser.lightning.BrowserApp; import acr.browser.lightning.preference.PreferenceManager; import acr.browser.lightning.utils.Utils; diff --git a/app/src/main/java/acr/browser/lightning/fragment/DisplaySettingsFragment.java b/app/src/main/java/acr/browser/lightning/settings/fragment/DisplaySettingsFragment.java similarity index 99% rename from app/src/main/java/acr/browser/lightning/fragment/DisplaySettingsFragment.java rename to app/src/main/java/acr/browser/lightning/settings/fragment/DisplaySettingsFragment.java index 0cdf6d1..575c203 100644 --- a/app/src/main/java/acr/browser/lightning/fragment/DisplaySettingsFragment.java +++ b/app/src/main/java/acr/browser/lightning/settings/fragment/DisplaySettingsFragment.java @@ -1,7 +1,7 @@ /* * Copyright 2014 A.C.R. Development */ -package acr.browser.lightning.fragment; +package acr.browser.lightning.settings.fragment; import android.app.Activity; import android.app.Dialog; diff --git a/app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java b/app/src/main/java/acr/browser/lightning/settings/fragment/GeneralSettingsFragment.java similarity index 99% rename from app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java rename to app/src/main/java/acr/browser/lightning/settings/fragment/GeneralSettingsFragment.java index 77446c0..7fdaef7 100644 --- a/app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java +++ b/app/src/main/java/acr/browser/lightning/settings/fragment/GeneralSettingsFragment.java @@ -1,7 +1,7 @@ /* * Copyright 2014 A.C.R. Development */ -package acr.browser.lightning.fragment; +package acr.browser.lightning.settings.fragment; import android.app.Activity; import android.app.Dialog; @@ -28,7 +28,7 @@ import javax.inject.Inject; import acr.browser.lightning.BuildConfig; import acr.browser.lightning.R; -import acr.browser.lightning.app.BrowserApp; +import acr.browser.lightning.BrowserApp; import acr.browser.lightning.constant.Constants; import acr.browser.lightning.dialog.BrowserDialog; import acr.browser.lightning.search.SearchEngineProvider; diff --git a/app/src/main/java/acr/browser/lightning/fragment/LightningPreferenceFragment.java b/app/src/main/java/acr/browser/lightning/settings/fragment/LightningPreferenceFragment.java similarity index 86% rename from app/src/main/java/acr/browser/lightning/fragment/LightningPreferenceFragment.java rename to app/src/main/java/acr/browser/lightning/settings/fragment/LightningPreferenceFragment.java index ab7c48d..0219267 100644 --- a/app/src/main/java/acr/browser/lightning/fragment/LightningPreferenceFragment.java +++ b/app/src/main/java/acr/browser/lightning/settings/fragment/LightningPreferenceFragment.java @@ -1,11 +1,11 @@ -package acr.browser.lightning.fragment; +package acr.browser.lightning.settings.fragment; import android.os.Bundle; import android.preference.PreferenceFragment; import javax.inject.Inject; -import acr.browser.lightning.app.BrowserApp; +import acr.browser.lightning.BrowserApp; import acr.browser.lightning.preference.PreferenceManager; /** diff --git a/app/src/main/java/acr/browser/lightning/fragment/PrivacySettingsFragment.java b/app/src/main/java/acr/browser/lightning/settings/fragment/PrivacySettingsFragment.java similarity index 99% rename from app/src/main/java/acr/browser/lightning/fragment/PrivacySettingsFragment.java rename to app/src/main/java/acr/browser/lightning/settings/fragment/PrivacySettingsFragment.java index d386d07..5a35eda 100644 --- a/app/src/main/java/acr/browser/lightning/fragment/PrivacySettingsFragment.java +++ b/app/src/main/java/acr/browser/lightning/settings/fragment/PrivacySettingsFragment.java @@ -1,7 +1,7 @@ /* * Copyright 2014 A.C.R. Development */ -package acr.browser.lightning.fragment; +package acr.browser.lightning.settings.fragment; import android.app.Activity; import android.app.Dialog; @@ -23,7 +23,7 @@ import com.anthonycr.bonsai.Schedulers; import javax.inject.Inject; import acr.browser.lightning.R; -import acr.browser.lightning.app.BrowserApp; +import acr.browser.lightning.BrowserApp; import acr.browser.lightning.database.history.HistoryModel; import acr.browser.lightning.dialog.BrowserDialog; import acr.browser.lightning.utils.Utils; diff --git a/app/src/main/java/acr/browser/lightning/utils/ProxyUtils.java b/app/src/main/java/acr/browser/lightning/utils/ProxyUtils.java index 9c7e8da..dada378 100644 --- a/app/src/main/java/acr/browser/lightning/utils/ProxyUtils.java +++ b/app/src/main/java/acr/browser/lightning/utils/ProxyUtils.java @@ -13,7 +13,7 @@ import javax.inject.Inject; import javax.inject.Singleton; import acr.browser.lightning.R; -import acr.browser.lightning.app.BrowserApp; +import acr.browser.lightning.BrowserApp; import acr.browser.lightning.constant.Constants; import acr.browser.lightning.dialog.BrowserDialog; import acr.browser.lightning.preference.PreferenceManager; diff --git a/app/src/main/java/acr/browser/lightning/utils/StringBuilderUtils.java b/app/src/main/java/acr/browser/lightning/utils/StringBuilderUtils.java index 77c5bb7..09ef24f 100644 --- a/app/src/main/java/acr/browser/lightning/utils/StringBuilderUtils.java +++ b/app/src/main/java/acr/browser/lightning/utils/StringBuilderUtils.java @@ -8,7 +8,7 @@ import android.support.annotation.NonNull; * API equality with the {@link String} * API. */ -class StringBuilderUtils { +public class StringBuilderUtils { private static final String SPACE = " "; private static final String EMPTY = ""; @@ -21,7 +21,7 @@ class StringBuilderUtils { * @param toReplace the string to replace. * @param replacement the replacement string. */ - static void replace(@NonNull StringBuilder stringBuilder, + public static void replace(@NonNull StringBuilder stringBuilder, @NonNull String toReplace, @NonNull String replacement) { int index = stringBuilder.indexOf(toReplace); diff --git a/app/src/main/java/acr/browser/lightning/utils/Utils.java b/app/src/main/java/acr/browser/lightning/utils/Utils.java index e780848..7086640 100644 --- a/app/src/main/java/acr/browser/lightning/utils/Utils.java +++ b/app/src/main/java/acr/browser/lightning/utils/Utils.java @@ -44,7 +44,7 @@ import java.text.SimpleDateFormat; import java.util.Date; import acr.browser.lightning.R; -import acr.browser.lightning.activity.MainActivity; +import acr.browser.lightning.MainActivity; import acr.browser.lightning.constant.Constants; import acr.browser.lightning.database.HistoryItem; import acr.browser.lightning.dialog.BrowserDialog; diff --git a/app/src/main/java/acr/browser/lightning/view/LightningChromeClient.java b/app/src/main/java/acr/browser/lightning/view/LightningChromeClient.java index 020813a..a17803c 100644 --- a/app/src/main/java/acr/browser/lightning/view/LightningChromeClient.java +++ b/app/src/main/java/acr/browser/lightning/view/LightningChromeClient.java @@ -25,7 +25,7 @@ import com.anthonycr.grant.PermissionsResultAction; import javax.inject.Inject; import acr.browser.lightning.R; -import acr.browser.lightning.app.BrowserApp; +import acr.browser.lightning.BrowserApp; import acr.browser.lightning.controller.UIController; import acr.browser.lightning.dialog.BrowserDialog; import acr.browser.lightning.favicon.FaviconModel; diff --git a/app/src/main/java/acr/browser/lightning/view/LightningView.java b/app/src/main/java/acr/browser/lightning/view/LightningView.java index 69b57b5..bbc4439 100644 --- a/app/src/main/java/acr/browser/lightning/view/LightningView.java +++ b/app/src/main/java/acr/browser/lightning/view/LightningView.java @@ -44,7 +44,7 @@ import java.util.Map; import javax.inject.Inject; -import acr.browser.lightning.app.BrowserApp; +import acr.browser.lightning.BrowserApp; import acr.browser.lightning.constant.BookmarkPage; import acr.browser.lightning.constant.Constants; import acr.browser.lightning.constant.DownloadsPage; diff --git a/app/src/main/java/acr/browser/lightning/view/LightningWebClient.java b/app/src/main/java/acr/browser/lightning/view/LightningWebClient.java index 5378019..db5e401 100644 --- a/app/src/main/java/acr/browser/lightning/view/LightningWebClient.java +++ b/app/src/main/java/acr/browser/lightning/view/LightningWebClient.java @@ -42,11 +42,11 @@ import javax.inject.Inject; import acr.browser.lightning.BuildConfig; import acr.browser.lightning.R; -import acr.browser.lightning.app.BrowserApp; +import acr.browser.lightning.BrowserApp; import acr.browser.lightning.constant.Constants; import acr.browser.lightning.controller.UIController; import acr.browser.lightning.dialog.BrowserDialog; -import acr.browser.lightning.utils.AdBlock; +import acr.browser.lightning.adblock.AdBlock; import acr.browser.lightning.utils.IntentUtils; import acr.browser.lightning.utils.Preconditions; import acr.browser.lightning.utils.ProxyUtils; diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 2fa0d62..be7042f 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -5,7 +5,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context=".activity.BrowserActivity"> + tools:context=".browser.activity.BrowserActivity">
    \ No newline at end of file From 3437a7fd7a62c2e398eb31385f111ef2db2952ee Mon Sep 17 00:00:00 2001 From: anthony restaino Date: Mon, 26 Jun 2017 22:47:13 -0400 Subject: [PATCH 50/56] Cleaning up the ResourcesUtils --- .../acr/browser/lightning/utils/ResourceUtils.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/acr/browser/lightning/utils/ResourceUtils.java b/app/src/main/java/acr/browser/lightning/utils/ResourceUtils.java index e2e85c8..5892e5c 100644 --- a/app/src/main/java/acr/browser/lightning/utils/ResourceUtils.java +++ b/app/src/main/java/acr/browser/lightning/utils/ResourceUtils.java @@ -4,11 +4,21 @@ import android.content.Context; import android.support.annotation.DimenRes; import android.support.annotation.NonNull; +/** + * Utils related to resources. + */ public final class ResourceUtils { private ResourceUtils() {} + /** + * Returns the dimension in pixels. + * + * @param context the context needed to get the dimension. + * @param res the resource to get. + * @return the dimension value in pixels. + */ public static int dimen(@NonNull Context context, @DimenRes int res) { - return Math.round(context.getResources().getDimension(res)); + return context.getResources().getDimensionPixelSize(res); } } From 7521415e942a383de95ba078b6a68a6ac23de78d Mon Sep 17 00:00:00 2001 From: anthony restaino Date: Mon, 26 Jun 2017 23:09:47 -0400 Subject: [PATCH 51/56] Cleaning up settings --- .../settings/activity/SettingsActivity.java | 12 ++++++------ .../settings/fragment/AboutSettingsFragment.java | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/acr/browser/lightning/settings/activity/SettingsActivity.java b/app/src/main/java/acr/browser/lightning/settings/activity/SettingsActivity.java index 8671c5b..687e9a3 100644 --- a/app/src/main/java/acr/browser/lightning/settings/activity/SettingsActivity.java +++ b/app/src/main/java/acr/browser/lightning/settings/activity/SettingsActivity.java @@ -23,12 +23,12 @@ import acr.browser.lightning.BrowserApp; public class SettingsActivity extends ThemableSettingsActivity { - @NonNull private static final List mFragments = new ArrayList<>(7); + @NonNull private static final List sFragments = new ArrayList<>(7); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - // this is a workaround for the Toolbar in PreferenceActitivty + // this is a workaround for the Toolbar in PreferenceActivity ViewGroup root = findViewById(android.R.id.content); LinearLayout content = (LinearLayout) root.getChildAt(0); LinearLayout toolbarContainer = (LinearLayout) View.inflate(this, R.layout.toolbar_settings, null); @@ -46,7 +46,7 @@ public class SettingsActivity extends ThemableSettingsActivity { @Override public void onBuildHeaders(List
    target) { loadHeadersFromResource(R.xml.preferences_headers, target); - mFragments.clear(); + sFragments.clear(); Iterator
    headerIterator = target.iterator(); while (headerIterator.hasNext()) { Header header = headerIterator.next(); @@ -59,17 +59,17 @@ public class SettingsActivity extends ThemableSettingsActivity { if (BrowserApp.isRelease()) { headerIterator.remove(); } else { - mFragments.add(header.fragment); + sFragments.add(header.fragment); } } else { - mFragments.add(header.fragment); + sFragments.add(header.fragment); } } } @Override protected boolean isValidFragment(String fragmentName) { - return mFragments.contains(fragmentName); + return sFragments.contains(fragmentName); } @Override diff --git a/app/src/main/java/acr/browser/lightning/settings/fragment/AboutSettingsFragment.java b/app/src/main/java/acr/browser/lightning/settings/fragment/AboutSettingsFragment.java index 2cf9bf1..483e253 100644 --- a/app/src/main/java/acr/browser/lightning/settings/fragment/AboutSettingsFragment.java +++ b/app/src/main/java/acr/browser/lightning/settings/fragment/AboutSettingsFragment.java @@ -9,13 +9,13 @@ import android.content.pm.PackageManager; import android.os.Bundle; import android.preference.Preference; import android.preference.PreferenceFragment; +import android.util.Log; import acr.browser.lightning.R; public class AboutSettingsFragment extends PreferenceFragment { - private Activity mActivity; - + private static final String TAG = "AboutSettingsFragment"; private static final String SETTINGS_VERSION = "pref_version"; @Override @@ -24,18 +24,18 @@ public class AboutSettingsFragment extends PreferenceFragment { // Load the preferences from an XML resource addPreferencesFromResource(R.xml.preference_about); - mActivity = getActivity(); - Preference version = findPreference(SETTINGS_VERSION); version.setSummary(getVersion()); } private String getVersion() { try { - PackageInfo p = mActivity.getPackageManager().getPackageInfo(mActivity.getPackageName(), 0); - return p.versionName; + Activity activity = getActivity(); + String packageName = activity.getPackageName(); + PackageInfo packageInfo = activity.getPackageManager().getPackageInfo(packageName, 0); + return packageInfo.versionName; } catch (PackageManager.NameNotFoundException e) { - e.printStackTrace(); + Log.e(TAG, "getVersion: error", e); return "1.0"; } } From 971ffbcb152653a1e85661af5df66fc5c77c8219 Mon Sep 17 00:00:00 2001 From: anthony restaino Date: Mon, 26 Jun 2017 23:19:50 -0400 Subject: [PATCH 52/56] Converting search engines to kotlin --- .../lightning/search/engine/AskSearch.java | 15 ------ .../lightning/search/engine/AskSearch.kt | 13 +++++ .../lightning/search/engine/BaiduSearch.java | 17 ------- .../lightning/search/engine/BaiduSearch.kt | 15 ++++++ .../search/engine/BaseSearchEngine.java | 51 ------------------- .../search/engine/BaseSearchEngine.kt | 15 ++++++ .../lightning/search/engine/BingSearch.java | 18 ------- .../lightning/search/engine/BingSearch.kt | 16 ++++++ .../lightning/search/engine/CustomSearch.java | 16 ------ .../lightning/search/engine/CustomSearch.kt | 12 +++++ .../search/engine/DuckLiteSearch.java | 17 ------- .../lightning/search/engine/DuckLiteSearch.kt | 15 ++++++ .../lightning/search/engine/DuckSearch.java | 17 ------- .../lightning/search/engine/DuckSearch.kt | 15 ++++++ .../lightning/search/engine/GoogleSearch.java | 16 ------ .../lightning/search/engine/GoogleSearch.kt | 15 ++++++ .../search/engine/StartPageMobileSearch.java | 15 ------ .../search/engine/StartPageMobileSearch.kt | 13 +++++ .../search/engine/StartPageSearch.java | 15 ------ .../search/engine/StartPageSearch.kt | 13 +++++ .../lightning/search/engine/YahooSearch.java | 18 ------- .../lightning/search/engine/YahooSearch.kt | 16 ++++++ .../lightning/search/engine/YandexSearch.java | 18 ------- .../lightning/search/engine/YandexSearch.kt | 16 ++++++ 24 files changed, 174 insertions(+), 233 deletions(-) delete mode 100644 app/src/main/java/acr/browser/lightning/search/engine/AskSearch.java create mode 100644 app/src/main/java/acr/browser/lightning/search/engine/AskSearch.kt delete mode 100644 app/src/main/java/acr/browser/lightning/search/engine/BaiduSearch.java create mode 100644 app/src/main/java/acr/browser/lightning/search/engine/BaiduSearch.kt delete mode 100644 app/src/main/java/acr/browser/lightning/search/engine/BaseSearchEngine.java create mode 100644 app/src/main/java/acr/browser/lightning/search/engine/BaseSearchEngine.kt delete mode 100644 app/src/main/java/acr/browser/lightning/search/engine/BingSearch.java create mode 100644 app/src/main/java/acr/browser/lightning/search/engine/BingSearch.kt delete mode 100644 app/src/main/java/acr/browser/lightning/search/engine/CustomSearch.java create mode 100644 app/src/main/java/acr/browser/lightning/search/engine/CustomSearch.kt delete mode 100644 app/src/main/java/acr/browser/lightning/search/engine/DuckLiteSearch.java create mode 100644 app/src/main/java/acr/browser/lightning/search/engine/DuckLiteSearch.kt delete mode 100644 app/src/main/java/acr/browser/lightning/search/engine/DuckSearch.java create mode 100644 app/src/main/java/acr/browser/lightning/search/engine/DuckSearch.kt delete mode 100644 app/src/main/java/acr/browser/lightning/search/engine/GoogleSearch.java create mode 100644 app/src/main/java/acr/browser/lightning/search/engine/GoogleSearch.kt delete mode 100644 app/src/main/java/acr/browser/lightning/search/engine/StartPageMobileSearch.java create mode 100644 app/src/main/java/acr/browser/lightning/search/engine/StartPageMobileSearch.kt delete mode 100644 app/src/main/java/acr/browser/lightning/search/engine/StartPageSearch.java create mode 100644 app/src/main/java/acr/browser/lightning/search/engine/StartPageSearch.kt delete mode 100644 app/src/main/java/acr/browser/lightning/search/engine/YahooSearch.java create mode 100644 app/src/main/java/acr/browser/lightning/search/engine/YahooSearch.kt delete mode 100644 app/src/main/java/acr/browser/lightning/search/engine/YandexSearch.java create mode 100644 app/src/main/java/acr/browser/lightning/search/engine/YandexSearch.kt diff --git a/app/src/main/java/acr/browser/lightning/search/engine/AskSearch.java b/app/src/main/java/acr/browser/lightning/search/engine/AskSearch.java deleted file mode 100644 index a20c805..0000000 --- a/app/src/main/java/acr/browser/lightning/search/engine/AskSearch.java +++ /dev/null @@ -1,15 +0,0 @@ -package acr.browser.lightning.search.engine; - -import acr.browser.lightning.R; -import acr.browser.lightning.constant.Constants; - -/** - * The Ask search engine. - */ -public class AskSearch extends BaseSearchEngine { - - public AskSearch() { - super("file:///android_asset/ask.png", Constants.ASK_SEARCH, R.string.search_engine_ask); - } - -} diff --git a/app/src/main/java/acr/browser/lightning/search/engine/AskSearch.kt b/app/src/main/java/acr/browser/lightning/search/engine/AskSearch.kt new file mode 100644 index 0000000..5ffb7bc --- /dev/null +++ b/app/src/main/java/acr/browser/lightning/search/engine/AskSearch.kt @@ -0,0 +1,13 @@ +package acr.browser.lightning.search.engine + +import acr.browser.lightning.R +import acr.browser.lightning.constant.Constants + +/** + * The Ask search engine. + */ +class AskSearch : BaseSearchEngine( + "file:///android_asset/ask.png", + Constants.ASK_SEARCH, + R.string.search_engine_ask +) diff --git a/app/src/main/java/acr/browser/lightning/search/engine/BaiduSearch.java b/app/src/main/java/acr/browser/lightning/search/engine/BaiduSearch.java deleted file mode 100644 index 2f4db83..0000000 --- a/app/src/main/java/acr/browser/lightning/search/engine/BaiduSearch.java +++ /dev/null @@ -1,17 +0,0 @@ -package acr.browser.lightning.search.engine; - -import acr.browser.lightning.R; -import acr.browser.lightning.constant.Constants; - -/** - * The Baidu search engine. - *

    - * See http://www.baidu.com/img/bdlogo.gif for the icon. - */ -public class BaiduSearch extends BaseSearchEngine { - - public BaiduSearch() { - super("file:///android_asset/baidu.png", Constants.BAIDU_SEARCH, R.string.search_engine_baidu); - } - -} diff --git a/app/src/main/java/acr/browser/lightning/search/engine/BaiduSearch.kt b/app/src/main/java/acr/browser/lightning/search/engine/BaiduSearch.kt new file mode 100644 index 0000000..f873663 --- /dev/null +++ b/app/src/main/java/acr/browser/lightning/search/engine/BaiduSearch.kt @@ -0,0 +1,15 @@ +package acr.browser.lightning.search.engine + +import acr.browser.lightning.R +import acr.browser.lightning.constant.Constants + +/** + * The Baidu search engine. + * + * See http://www.baidu.com/img/bdlogo.gif for the icon. + */ +class BaiduSearch : BaseSearchEngine( + "file:///android_asset/baidu.png", + Constants.BAIDU_SEARCH, + R.string.search_engine_baidu +) diff --git a/app/src/main/java/acr/browser/lightning/search/engine/BaseSearchEngine.java b/app/src/main/java/acr/browser/lightning/search/engine/BaseSearchEngine.java deleted file mode 100644 index 92cb5e9..0000000 --- a/app/src/main/java/acr/browser/lightning/search/engine/BaseSearchEngine.java +++ /dev/null @@ -1,51 +0,0 @@ -package acr.browser.lightning.search.engine; - -import android.support.annotation.NonNull; -import android.support.annotation.StringRes; - -import acr.browser.lightning.utils.Preconditions; - -/** - * A class representative of a search engine. - *

    - * Contains three key pieces of information: - *

      - *
    • The icon shown for the search engine, should point to a local assets URL.
    • - *
    • The query URL for the search engine, the query will be appended to the end.
    • - *
    • The title string resource for the search engine.
    • - *
    - */ -public class BaseSearchEngine { - - @NonNull private final String mIconUrl; - @NonNull private final String mQueryUrl; - @StringRes private final int mTitleRes; - - BaseSearchEngine(@NonNull String iconUrl, - @NonNull String queryUrl, - @StringRes int titleRes) { - - Preconditions.checkNonNull(iconUrl); - Preconditions.checkNonNull(queryUrl); - - mIconUrl = iconUrl; - mQueryUrl = queryUrl; - mTitleRes = titleRes; - } - - @NonNull - public final String getIconUrl() { - return mIconUrl; - } - - @NonNull - public final String getQueryUrl() { - return mQueryUrl; - } - - @StringRes - public final int getTitleRes() { - return mTitleRes; - } - -} diff --git a/app/src/main/java/acr/browser/lightning/search/engine/BaseSearchEngine.kt b/app/src/main/java/acr/browser/lightning/search/engine/BaseSearchEngine.kt new file mode 100644 index 0000000..b066e55 --- /dev/null +++ b/app/src/main/java/acr/browser/lightning/search/engine/BaseSearchEngine.kt @@ -0,0 +1,15 @@ +package acr.browser.lightning.search.engine + +import android.support.annotation.StringRes + +/** + * A class representative of a search engine. + * + * Contains three key pieces of information: + * * The icon shown for the search engine, should point to a local assets URL. + * * The query URL for the search engine, the query will be appended to the end. + * * The title string resource for the search engine. + */ +open class BaseSearchEngine internal constructor(val iconUrl: String, + val queryUrl: String, + @StringRes val titleRes: Int) diff --git a/app/src/main/java/acr/browser/lightning/search/engine/BingSearch.java b/app/src/main/java/acr/browser/lightning/search/engine/BingSearch.java deleted file mode 100644 index 3b2d17d..0000000 --- a/app/src/main/java/acr/browser/lightning/search/engine/BingSearch.java +++ /dev/null @@ -1,18 +0,0 @@ -package acr.browser.lightning.search.engine; - -import acr.browser.lightning.R; -import acr.browser.lightning.constant.Constants; - -/** - * The Bing search engine. - *

    - * See http://upload.wikimedia.org/wikipedia/commons/thumb/b/b1/Bing_logo_%282013%29.svg/500px-Bing_logo_%282013%29.svg.png - * for the icon. - */ -public class BingSearch extends BaseSearchEngine { - - public BingSearch() { - super("file:///android_asset/bing.png", Constants.BING_SEARCH, R.string.search_engine_bing); - } - -} diff --git a/app/src/main/java/acr/browser/lightning/search/engine/BingSearch.kt b/app/src/main/java/acr/browser/lightning/search/engine/BingSearch.kt new file mode 100644 index 0000000..466a263 --- /dev/null +++ b/app/src/main/java/acr/browser/lightning/search/engine/BingSearch.kt @@ -0,0 +1,16 @@ +package acr.browser.lightning.search.engine + +import acr.browser.lightning.R +import acr.browser.lightning.constant.Constants + +/** + * The Bing search engine. + * + * See http://upload.wikimedia.org/wikipedia/commons/thumb/b/b1/Bing_logo_%282013%29.svg/500px-Bing_logo_%282013%29.svg.png + * for the icon. + */ +class BingSearch : BaseSearchEngine( + "file:///android_asset/bing.png", + Constants.BING_SEARCH, + R.string.search_engine_bing +) diff --git a/app/src/main/java/acr/browser/lightning/search/engine/CustomSearch.java b/app/src/main/java/acr/browser/lightning/search/engine/CustomSearch.java deleted file mode 100644 index baf6e5c..0000000 --- a/app/src/main/java/acr/browser/lightning/search/engine/CustomSearch.java +++ /dev/null @@ -1,16 +0,0 @@ -package acr.browser.lightning.search.engine; - -import android.support.annotation.NonNull; - -import acr.browser.lightning.R; - -/** - * A custom search engine. - */ -public class CustomSearch extends BaseSearchEngine { - - public CustomSearch(@NonNull String queryUrl) { - super("file:///android_asset/lightning.png", queryUrl, R.string.search_engine_custom); - } - -} diff --git a/app/src/main/java/acr/browser/lightning/search/engine/CustomSearch.kt b/app/src/main/java/acr/browser/lightning/search/engine/CustomSearch.kt new file mode 100644 index 0000000..f48de75 --- /dev/null +++ b/app/src/main/java/acr/browser/lightning/search/engine/CustomSearch.kt @@ -0,0 +1,12 @@ +package acr.browser.lightning.search.engine + +import acr.browser.lightning.R + +/** + * A custom search engine. + */ +class CustomSearch(queryUrl: String) : BaseSearchEngine( + "file:///android_asset/lightning.png", + queryUrl, + R.string.search_engine_custom +) diff --git a/app/src/main/java/acr/browser/lightning/search/engine/DuckLiteSearch.java b/app/src/main/java/acr/browser/lightning/search/engine/DuckLiteSearch.java deleted file mode 100644 index a844031..0000000 --- a/app/src/main/java/acr/browser/lightning/search/engine/DuckLiteSearch.java +++ /dev/null @@ -1,17 +0,0 @@ -package acr.browser.lightning.search.engine; - -import acr.browser.lightning.R; -import acr.browser.lightning.constant.Constants; - -/** - * The DuckDuckGo Lite search engine. - *

    - * See https://duckduckgo.com/assets/logo_homepage.normal.v101.png for the icon. - */ -public class DuckLiteSearch extends BaseSearchEngine { - - public DuckLiteSearch() { - super("file:///android_asset/duckduckgo.png", Constants.DUCK_LITE_SEARCH, R.string.search_engine_duckduckgo_lite); - } - -} diff --git a/app/src/main/java/acr/browser/lightning/search/engine/DuckLiteSearch.kt b/app/src/main/java/acr/browser/lightning/search/engine/DuckLiteSearch.kt new file mode 100644 index 0000000..2135a6f --- /dev/null +++ b/app/src/main/java/acr/browser/lightning/search/engine/DuckLiteSearch.kt @@ -0,0 +1,15 @@ +package acr.browser.lightning.search.engine + +import acr.browser.lightning.R +import acr.browser.lightning.constant.Constants + +/** + * The DuckDuckGo Lite search engine. + * + * See https://duckduckgo.com/assets/logo_homepage.normal.v101.png for the icon. + */ +class DuckLiteSearch : BaseSearchEngine( + "file:///android_asset/duckduckgo.png", + Constants.DUCK_LITE_SEARCH, + R.string.search_engine_duckduckgo_lite +) diff --git a/app/src/main/java/acr/browser/lightning/search/engine/DuckSearch.java b/app/src/main/java/acr/browser/lightning/search/engine/DuckSearch.java deleted file mode 100644 index dff9b7d..0000000 --- a/app/src/main/java/acr/browser/lightning/search/engine/DuckSearch.java +++ /dev/null @@ -1,17 +0,0 @@ -package acr.browser.lightning.search.engine; - -import acr.browser.lightning.R; -import acr.browser.lightning.constant.Constants; - -/** - * The DuckDuckGo search engine. - *

    - * See https://duckduckgo.com/assets/logo_homepage.normal.v101.png for the icon. - */ -public class DuckSearch extends BaseSearchEngine { - - public DuckSearch() { - super("file:///android_asset/duckduckgo.png", Constants.DUCK_SEARCH, R.string.search_engine_duckduckgo); - } - -} diff --git a/app/src/main/java/acr/browser/lightning/search/engine/DuckSearch.kt b/app/src/main/java/acr/browser/lightning/search/engine/DuckSearch.kt new file mode 100644 index 0000000..dd110c7 --- /dev/null +++ b/app/src/main/java/acr/browser/lightning/search/engine/DuckSearch.kt @@ -0,0 +1,15 @@ +package acr.browser.lightning.search.engine + +import acr.browser.lightning.R +import acr.browser.lightning.constant.Constants + +/** + * The DuckDuckGo search engine. + * + * See https://duckduckgo.com/assets/logo_homepage.normal.v101.png for the icon. + */ +class DuckSearch : BaseSearchEngine( + "file:///android_asset/duckduckgo.png", + Constants.DUCK_SEARCH, + R.string.search_engine_duckduckgo +) diff --git a/app/src/main/java/acr/browser/lightning/search/engine/GoogleSearch.java b/app/src/main/java/acr/browser/lightning/search/engine/GoogleSearch.java deleted file mode 100644 index efa6def..0000000 --- a/app/src/main/java/acr/browser/lightning/search/engine/GoogleSearch.java +++ /dev/null @@ -1,16 +0,0 @@ -package acr.browser.lightning.search.engine; - -import acr.browser.lightning.R; -import acr.browser.lightning.constant.Constants; - -/** - * The Google search engine. - *

    - * See https://www.google.com/images/srpr/logo11w.png for the icon. - */ -public class GoogleSearch extends BaseSearchEngine { - - public GoogleSearch() { - super("file:///android_asset/google.png", Constants.GOOGLE_SEARCH, R.string.search_engine_google); - } -} diff --git a/app/src/main/java/acr/browser/lightning/search/engine/GoogleSearch.kt b/app/src/main/java/acr/browser/lightning/search/engine/GoogleSearch.kt new file mode 100644 index 0000000..79547a1 --- /dev/null +++ b/app/src/main/java/acr/browser/lightning/search/engine/GoogleSearch.kt @@ -0,0 +1,15 @@ +package acr.browser.lightning.search.engine + +import acr.browser.lightning.R +import acr.browser.lightning.constant.Constants + +/** + * The Google search engine. + * + * See https://www.google.com/images/srpr/logo11w.png for the icon. + */ +class GoogleSearch : BaseSearchEngine( + "file:///android_asset/google.png", + Constants.GOOGLE_SEARCH, + R.string.search_engine_google +) diff --git a/app/src/main/java/acr/browser/lightning/search/engine/StartPageMobileSearch.java b/app/src/main/java/acr/browser/lightning/search/engine/StartPageMobileSearch.java deleted file mode 100644 index a961339..0000000 --- a/app/src/main/java/acr/browser/lightning/search/engine/StartPageMobileSearch.java +++ /dev/null @@ -1,15 +0,0 @@ -package acr.browser.lightning.search.engine; - -import acr.browser.lightning.R; -import acr.browser.lightning.constant.Constants; - -/** - * The StartPage mobile search engine. - */ -public class StartPageMobileSearch extends BaseSearchEngine { - - public StartPageMobileSearch() { - super("file:///android_asset/startpage.png", Constants.STARTPAGE_MOBILE_SEARCH, R.string.search_engine_startpage_mobile); - } - -} diff --git a/app/src/main/java/acr/browser/lightning/search/engine/StartPageMobileSearch.kt b/app/src/main/java/acr/browser/lightning/search/engine/StartPageMobileSearch.kt new file mode 100644 index 0000000..f83bab4 --- /dev/null +++ b/app/src/main/java/acr/browser/lightning/search/engine/StartPageMobileSearch.kt @@ -0,0 +1,13 @@ +package acr.browser.lightning.search.engine + +import acr.browser.lightning.R +import acr.browser.lightning.constant.Constants + +/** + * The StartPage mobile search engine. + */ +class StartPageMobileSearch : BaseSearchEngine( + "file:///android_asset/startpage.png", + Constants.STARTPAGE_MOBILE_SEARCH, + R.string.search_engine_startpage_mobile +) diff --git a/app/src/main/java/acr/browser/lightning/search/engine/StartPageSearch.java b/app/src/main/java/acr/browser/lightning/search/engine/StartPageSearch.java deleted file mode 100644 index bd48e50..0000000 --- a/app/src/main/java/acr/browser/lightning/search/engine/StartPageSearch.java +++ /dev/null @@ -1,15 +0,0 @@ -package acr.browser.lightning.search.engine; - -import acr.browser.lightning.R; -import acr.browser.lightning.constant.Constants; - -/** - * The StartPage search engine. - */ -public class StartPageSearch extends BaseSearchEngine { - - public StartPageSearch() { - super("file:///android_asset/startpage.png", Constants.STARTPAGE_SEARCH, R.string.search_engine_startpage); - } - -} diff --git a/app/src/main/java/acr/browser/lightning/search/engine/StartPageSearch.kt b/app/src/main/java/acr/browser/lightning/search/engine/StartPageSearch.kt new file mode 100644 index 0000000..a167155 --- /dev/null +++ b/app/src/main/java/acr/browser/lightning/search/engine/StartPageSearch.kt @@ -0,0 +1,13 @@ +package acr.browser.lightning.search.engine + +import acr.browser.lightning.R +import acr.browser.lightning.constant.Constants + +/** + * The StartPage search engine. + */ +class StartPageSearch : BaseSearchEngine( + "file:///android_asset/startpage.png", + Constants.STARTPAGE_SEARCH, + R.string.search_engine_startpage +) diff --git a/app/src/main/java/acr/browser/lightning/search/engine/YahooSearch.java b/app/src/main/java/acr/browser/lightning/search/engine/YahooSearch.java deleted file mode 100644 index 74b1a81..0000000 --- a/app/src/main/java/acr/browser/lightning/search/engine/YahooSearch.java +++ /dev/null @@ -1,18 +0,0 @@ -package acr.browser.lightning.search.engine; - -import acr.browser.lightning.R; -import acr.browser.lightning.constant.Constants; - -/** - * The Yahoo search engine. - *

    - * See http://upload.wikimedia.org/wikipedia/commons/thumb/2/24/Yahoo%21_logo.svg/799px-Yahoo%21_logo.svg.png - * for the icon. - */ -public class YahooSearch extends BaseSearchEngine { - - public YahooSearch() { - super("file:///android_asset/yahoo.png", Constants.YAHOO_SEARCH, R.string.search_engine_yahoo); - } - -} diff --git a/app/src/main/java/acr/browser/lightning/search/engine/YahooSearch.kt b/app/src/main/java/acr/browser/lightning/search/engine/YahooSearch.kt new file mode 100644 index 0000000..2355ab6 --- /dev/null +++ b/app/src/main/java/acr/browser/lightning/search/engine/YahooSearch.kt @@ -0,0 +1,16 @@ +package acr.browser.lightning.search.engine + +import acr.browser.lightning.R +import acr.browser.lightning.constant.Constants + +/** + * The Yahoo search engine. + * + * See http://upload.wikimedia.org/wikipedia/commons/thumb/2/24/Yahoo%21_logo.svg/799px-Yahoo%21_logo.svg.png + * for the icon. + */ +class YahooSearch : BaseSearchEngine( + "file:///android_asset/yahoo.png", + Constants.YAHOO_SEARCH, + R.string.search_engine_yahoo +) diff --git a/app/src/main/java/acr/browser/lightning/search/engine/YandexSearch.java b/app/src/main/java/acr/browser/lightning/search/engine/YandexSearch.java deleted file mode 100644 index ff746e7..0000000 --- a/app/src/main/java/acr/browser/lightning/search/engine/YandexSearch.java +++ /dev/null @@ -1,18 +0,0 @@ -package acr.browser.lightning.search.engine; - -import acr.browser.lightning.R; -import acr.browser.lightning.constant.Constants; - -/** - * The Yandex search engine. - *

    - * See http://upload.wikimedia.org/wikipedia/commons/thumb/9/91/Yandex.svg/600px-Yandex.svg.png - * for the icon. - */ -public class YandexSearch extends BaseSearchEngine { - - public YandexSearch() { - super("file:///android_asset/yandex.png", Constants.YANDEX_SEARCH, R.string.search_engine_yandex); - } - -} diff --git a/app/src/main/java/acr/browser/lightning/search/engine/YandexSearch.kt b/app/src/main/java/acr/browser/lightning/search/engine/YandexSearch.kt new file mode 100644 index 0000000..8d58957 --- /dev/null +++ b/app/src/main/java/acr/browser/lightning/search/engine/YandexSearch.kt @@ -0,0 +1,16 @@ +package acr.browser.lightning.search.engine + +import acr.browser.lightning.R +import acr.browser.lightning.constant.Constants + +/** + * The Yandex search engine. + * + * See http://upload.wikimedia.org/wikipedia/commons/thumb/9/91/Yandex.svg/600px-Yandex.svg.png + * for the icon. + */ +class YandexSearch : BaseSearchEngine( + "file:///android_asset/yandex.png", + Constants.YANDEX_SEARCH, + R.string.search_engine_yandex +) From 6492fd43b05bef42edc6b3b793f0ffc6b047ca28 Mon Sep 17 00:00:00 2001 From: Luca Stefani Date: Tue, 27 Jun 2017 15:04:44 +0200 Subject: [PATCH 53/56] GoogleSuggestions: Switch to UTF-8 encoding --- .../lightning/search/suggestions/GoogleSuggestionsModel.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/acr/browser/lightning/search/suggestions/GoogleSuggestionsModel.java b/app/src/main/java/acr/browser/lightning/search/suggestions/GoogleSuggestionsModel.java index 1128766..53ce9b9 100644 --- a/app/src/main/java/acr/browser/lightning/search/suggestions/GoogleSuggestionsModel.java +++ b/app/src/main/java/acr/browser/lightning/search/suggestions/GoogleSuggestionsModel.java @@ -20,7 +20,7 @@ import acr.browser.lightning.database.HistoryItem; */ public class GoogleSuggestionsModel extends BaseSuggestionsModel { - @NonNull private static final String ENCODING = "ISO-8859-1"; + @NonNull private static final String ENCODING = "UTF-8"; @Nullable private static XmlPullParser sXpp; @NonNull private final String mSearchSubtitle; @@ -31,7 +31,7 @@ public class GoogleSuggestionsModel extends BaseSuggestionsModel { @NonNull protected String createQueryUrl(@NonNull String query, @NonNull String language) { - return "https://suggestqueries.google.com/complete/search?output=toolbar&oe=latin1&hl=" + return "https://suggestqueries.google.com/complete/search?output=toolbar&hl=" + language + "&q=" + query; } From ad47bc1fdb40eb0e1fdc6e96040c695d0bd63ea4 Mon Sep 17 00:00:00 2001 From: anthony restaino Date: Tue, 27 Jun 2017 21:38:24 -0400 Subject: [PATCH 54/56] Breaking out parsing code into different method --- .../browser/lightning/adblock/AdBlock.java | 75 +++++++++++-------- 1 file changed, 44 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/acr/browser/lightning/adblock/AdBlock.java b/app/src/main/java/acr/browser/lightning/adblock/AdBlock.java index 6cd948f..698b231 100644 --- a/app/src/main/java/acr/browser/lightning/adblock/AdBlock.java +++ b/app/src/main/java/acr/browser/lightning/adblock/AdBlock.java @@ -16,7 +16,9 @@ import java.io.IOException; import java.io.InputStreamReader; import java.net.URI; import java.net.URISyntaxException; +import java.util.ArrayList; import java.util.HashSet; +import java.util.List; import java.util.Set; import javax.inject.Inject; @@ -134,42 +136,16 @@ public class AdBlock { String line; long time = System.currentTimeMillis(); + final List domains = new ArrayList<>(1); + while ((line = reader.readLine()) != null) { lineBuilder.append(line); - if (!StringBuilderUtils.isEmpty(lineBuilder) && - !StringBuilderUtils.startsWith(lineBuilder, COMMENT)) { - StringBuilderUtils.replace(lineBuilder, LOCAL_IP_V4, EMPTY); - StringBuilderUtils.replace(lineBuilder, LOCAL_IP_V4_ALT, EMPTY); - StringBuilderUtils.replace(lineBuilder, LOCAL_IP_V6, EMPTY); - StringBuilderUtils.replace(lineBuilder, TAB, EMPTY); - - int comment = lineBuilder.indexOf(COMMENT); - if (comment >= 0) { - lineBuilder.replace(comment, lineBuilder.length(), EMPTY); - } - - StringBuilderUtils.trim(lineBuilder); - - if (!StringBuilderUtils.isEmpty(lineBuilder) && - !StringBuilderUtils.equals(lineBuilder, LOCALHOST)) { - while (StringBuilderUtils.contains(lineBuilder, SPACE)) { - int space = lineBuilder.indexOf(SPACE); - StringBuilder partial = StringBuilderUtils.substring(lineBuilder, 0, space); - StringBuilderUtils.trim(partial); - - String partialLine = partial.toString(); - mBlockedDomainsList.add(partialLine); - StringBuilderUtils.replace(lineBuilder, partialLine, EMPTY); - StringBuilderUtils.trim(lineBuilder); - } - if (lineBuilder.length() > 0) { - mBlockedDomainsList.add(lineBuilder.toString()); - } - } - } + parseString(lineBuilder, domains); lineBuilder.setLength(0); } + + mBlockedDomainsList.addAll(domains); Log.d(TAG, "Loaded ad list in: " + (System.currentTimeMillis() - time) + " ms"); } catch (IOException e) { Log.wtf(TAG, "Reading blocked domains list from file '" @@ -181,4 +157,41 @@ public class AdBlock { }); } + private static void parseString(@NonNull StringBuilder lineBuilder, @NonNull List parsedList) { + if (!StringBuilderUtils.isEmpty(lineBuilder) && + !StringBuilderUtils.startsWith(lineBuilder, COMMENT)) { + StringBuilderUtils.replace(lineBuilder, LOCAL_IP_V4, EMPTY); + StringBuilderUtils.replace(lineBuilder, LOCAL_IP_V4_ALT, EMPTY); + StringBuilderUtils.replace(lineBuilder, LOCAL_IP_V6, EMPTY); + StringBuilderUtils.replace(lineBuilder, TAB, EMPTY); + + int comment = lineBuilder.indexOf(COMMENT); + if (comment >= 0) { + lineBuilder.replace(comment, lineBuilder.length(), EMPTY); + } + + StringBuilderUtils.trim(lineBuilder); + + if (!StringBuilderUtils.isEmpty(lineBuilder) && + !StringBuilderUtils.equals(lineBuilder, LOCALHOST)) { + while (StringBuilderUtils.contains(lineBuilder, SPACE)) { + int space = lineBuilder.indexOf(SPACE); + StringBuilder partial = StringBuilderUtils.substring(lineBuilder, 0, space); + StringBuilderUtils.trim(partial); + + String partialLine = partial.toString(); + + // Add string to list + parsedList.add(partialLine); + StringBuilderUtils.replace(lineBuilder, partialLine, EMPTY); + StringBuilderUtils.trim(lineBuilder); + } + if (lineBuilder.length() > 0) { + // Add string to list. + parsedList.add(lineBuilder.toString()); + } + } + } + } + } From d7401e2106b4d96cc6e1fbe406da7e7746546599 Mon Sep 17 00:00:00 2001 From: anthony restaino Date: Wed, 28 Jun 2017 21:43:56 -0400 Subject: [PATCH 55/56] Bump for bugfix --- build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index b262873..cda7375 100644 --- a/build.gradle +++ b/build.gradle @@ -23,7 +23,7 @@ ext { targetSdkVersion = 26 buildToolsVersion = '26.0.0' - versionName = '4.5.0' - versionCode_lite = 97 - versionCode_plus = 95 + versionName = '4.5.1' + versionCode_lite = 98 + versionCode_plus = 96 } From d7d2a5881552613fed291a923bd8fd3b39fcf89b Mon Sep 17 00:00:00 2001 From: anthony restaino Date: Wed, 28 Jun 2017 21:57:33 -0400 Subject: [PATCH 56/56] Adding 4.5.1 release info --- CHANGELOG.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d1521c..c83a801 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,18 @@ Change Log ========== +Version 4.5.1 *(2017-06-28)* +---------------------------- +- Fixed bug with folders disappearing on bookmark homepage +- Updated history page +- Updated bookmark page +- Updating target to Android O +- Updating default bookmark favicons +- Fixed occasional bug with bookmark long press +- Updated downloads page design +- Enhanced keyboard shortcuts +- Fixed bug in google search suggestions for certain languages + Version 4.5.0 *(2017-06-08)* ---------------------------- - Translation updates