diff --git a/app/src/main/java/com/darkweb/genesissearchengine/appManager/homeManager/homeController.java b/app/src/main/java/com/darkweb/genesissearchengine/appManager/homeManager/homeController.java index 6473a371..f5ac594f 100755 --- a/app/src/main/java/com/darkweb/genesissearchengine/appManager/homeManager/homeController.java +++ b/app/src/main/java/com/darkweb/genesissearchengine/appManager/homeManager/homeController.java @@ -441,45 +441,6 @@ public class homeController extends AppCompatActivity implements ComponentCallba } } - public void onSwitchSearch(View view){ - dataController.getInstance().invokePrefs(dataEnums.ePreferencesCommands.M_SET_BOOL, Arrays.asList(keys.SETTING_ENGINE_SWITCHED,true)); - pluginController.getInstance().logEvent(strings.EVENT_SEARCH_SWITCH); - - if(status.sSettingSearchStatus.equals(constants.CONST_BACKEND_GOOGLE_URL)) - { - status.sSettingSearchStatus = constants.CONST_BACKEND_GENESIS_URL; - mHomeViewController.onUpdateLogo(); - dataController.getInstance().invokePrefs(dataEnums.ePreferencesCommands.M_SET_STRING, Arrays.asList(keys.SETTING_SEARCH_ENGINE,constants.CONST_BACKEND_GENESIS_URL)); - onHomeButton(null); - } - else if(status.sSettingSearchStatus.equals(constants.CONST_BACKEND_GENESIS_URL)) - { - status.sSettingSearchStatus = constants.CONST_BACKEND_DUCK_DUCK_GO_URL; - if(pluginController.getInstance().isOrbotRunning()) - { - mHomeViewController.onUpdateLogo(); - dataController.getInstance().invokePrefs(dataEnums.ePreferencesCommands.M_SET_STRING, Arrays.asList(keys.SETTING_SEARCH_ENGINE,constants.CONST_BACKEND_DUCK_DUCK_GO_URL)); - onHomeButton(null); - } - else { - pluginController.getInstance().MessageManagerHandler(homeController.this, Collections.singletonList(constants.CONST_BACKEND_DUCK_DUCK_GO_URL),enums.etype.start_orbot); - } - } - else - { - status.sSettingSearchStatus = constants.CONST_BACKEND_GOOGLE_URL; - if(pluginController.getInstance().isOrbotRunning()) - { - mHomeViewController.onUpdateLogo(); - dataController.getInstance().invokePrefs(dataEnums.ePreferencesCommands.M_SET_STRING, Arrays.asList(keys.SETTING_SEARCH_ENGINE,constants.CONST_BACKEND_GOOGLE_URL)); - onHomeButton(null); - } - else { - pluginController.getInstance().MessageManagerHandler(homeController.this,Collections.singletonList(constants.CONST_BACKEND_GOOGLE_URL),enums.etype.start_orbot); - } - } - } - /*Activity States*/ public void onReload(View view){ diff --git a/app/src/main/java/com/darkweb/genesissearchengine/appManager/homeManager/homeModel.java b/app/src/main/java/com/darkweb/genesissearchengine/appManager/homeManager/homeModel.java index 25c39428..2c1de034 100755 --- a/app/src/main/java/com/darkweb/genesissearchengine/appManager/homeManager/homeModel.java +++ b/app/src/main/java/com/darkweb/genesissearchengine/appManager/homeManager/homeModel.java @@ -31,15 +31,7 @@ class homeModel ex.printStackTrace(); } - if(status.sSettingSearchStatus.equals(constants.CONST_BACKEND_GOOGLE_URL)){ - return getSearchEngine()+"search?q="+url.replaceAll(" ","+"); - } - else if(status.sSettingSearchStatus.equals(constants.CONST_BACKEND_GENESIS_URL)){ - return getSearchEngine()+"/search?s_type=all&p_num=1&q="+url.replaceAll(" ","+"); - } - else{ - return getSearchEngine()+"?q="+url.replaceAll(" ","+"); - } + return constants.CONST_BACKEND_GOOGLE_URL.replace("$s",url.replaceAll(" ","+")); } diff --git a/app/src/main/java/com/darkweb/genesissearchengine/appManager/homeManager/homeViewController.java b/app/src/main/java/com/darkweb/genesissearchengine/appManager/homeManager/homeViewController.java index 8bbe1c47..f1d7cfb0 100755 --- a/app/src/main/java/com/darkweb/genesissearchengine/appManager/homeManager/homeViewController.java +++ b/app/src/main/java/com/darkweb/genesissearchengine/appManager/homeManager/homeViewController.java @@ -662,9 +662,9 @@ class homeViewController if(msg.what == messages.MESSAGE_ON_URL_LOAD) { if(status.sSettingRedirectStatus.equals(strings.GENERIC_EMPTY_STR)){ - mEvent.invokeObserver(Collections.singletonList(status.sSettingSearchStatus), enums.etype.on_url_load); + mEvent.invokeObserver(Collections.singletonList(helperMethod.getDomainName(status.sSettingSearchStatus)), enums.etype.on_url_load); }else { - mEvent.invokeObserver(Collections.singletonList(status.sSettingRedirectStatus), enums.etype.on_url_load); + mEvent.invokeObserver(Collections.singletonList(helperMethod.getDomainName(status.sSettingRedirectStatus)), enums.etype.on_url_load); } } if(msg.what == messages.MESSAGE_UPDATE_LOADING_TEXT) diff --git a/app/src/main/java/com/darkweb/genesissearchengine/appManager/settingManager/searchEngineManager/settingSearchController.java b/app/src/main/java/com/darkweb/genesissearchengine/appManager/settingManager/searchEngineManager/settingSearchController.java index 2c603a55..410751fc 100644 --- a/app/src/main/java/com/darkweb/genesissearchengine/appManager/settingManager/searchEngineManager/settingSearchController.java +++ b/app/src/main/java/com/darkweb/genesissearchengine/appManager/settingManager/searchEngineManager/settingSearchController.java @@ -3,20 +3,28 @@ package com.darkweb.genesissearchengine.appManager.settingManager.searchEngineMa import android.content.Intent; import android.os.Bundle; import android.view.View; +import android.widget.RadioButton; +import android.widget.Spinner; import androidx.appcompat.app.AppCompatActivity; import com.darkweb.genesissearchengine.appManager.activityContextManager; +import com.darkweb.genesissearchengine.constants.constants; import com.darkweb.genesissearchengine.constants.enums; import com.darkweb.genesissearchengine.helperManager.eventObserver; import com.darkweb.genesissearchengine.pluginManager.pluginController; import com.example.myapplication.R; +import com.google.android.material.switchmaterial.SwitchMaterial; +import java.util.ArrayList; import java.util.List; public class settingSearchController extends AppCompatActivity { /* PRIVATE VARIABLES */ + private ArrayList mSearchEngines = new ArrayList<>(); + private SwitchMaterial mSearchHistory; + private SwitchMaterial mSearchSuggestions; private settingSearchModel mSettingSearchModel; private settingSearchViewController mSettingSearchViewController; @@ -30,11 +38,49 @@ public class settingSearchController extends AppCompatActivity { } public void viewsInitializations() { - mSettingSearchViewController = new settingSearchViewController(this, new settingSearchViewCallback()); + mSearchEngines.add(findViewById(R.id.mRadioSearch_1)); + mSearchEngines.add(findViewById(R.id.mRadioSearch_2)); + mSearchEngines.add(findViewById(R.id.mRadioSearch_3)); + mSearchEngines.add(findViewById(R.id.mRadioSearch_4)); + mSearchEngines.add(findViewById(R.id.mRadioSearch_5)); + mSearchHistory = findViewById(R.id.pSearchHistory); + mSearchSuggestions = findViewById(R.id.pSearchSuggestions); + mSettingSearchViewController = new settingSearchViewController(this, new settingSearchViewCallback(), mSearchEngines, mSearchHistory, mSearchSuggestions); mSettingSearchModel = new settingSearchModel(new settingSearchModelCallback()); } + public void onSelectSearchEngine(View view) { + if(view.getId() == R.id.pOption1){ + mSettingSearchModel.onSetSearchEngine(constants.CONST_BACKEND_GENESIS_URL); + } + else if(view.getId() == R.id.pOption2){ + mSettingSearchModel.onSetSearchEngine(constants.CONST_BACKEND_DUCK_DUCK_GO_URL); + } + else if(view.getId() == R.id.pOption3){ + mSettingSearchModel.onSetSearchEngine(constants.CONST_BACKEND_GOOGLE_URL); + } + else if(view.getId() == R.id.pOption4){ + mSettingSearchModel.onSetSearchEngine(constants.CONST_BACKEND_BING_URL); + } + else if(view.getId() == R.id.pOption5){ + mSettingSearchModel.onSetSearchEngine(constants.CONST_BACKEND_WIKI_URL); + } + + mSettingSearchViewController.resetSearchEngine(); + mSettingSearchViewController.initSearchEngine(); + } + + public void setSearchHistory(View view){ + mSettingSearchModel.setSearchHistory(!mSearchHistory.isChecked()); + mSearchHistory.toggle(); + } + + public void setSearchStatus(View view){ + mSettingSearchModel.setSearchStatus(!mSearchSuggestions.isChecked()); + mSearchSuggestions.toggle(); + } + /* LISTENERS */ public class settingSearchViewCallback implements eventObserver.eventListener{ diff --git a/app/src/main/java/com/darkweb/genesissearchengine/appManager/settingManager/searchEngineManager/settingSearchModel.java b/app/src/main/java/com/darkweb/genesissearchengine/appManager/settingManager/searchEngineManager/settingSearchModel.java index a2181408..27c73270 100644 --- a/app/src/main/java/com/darkweb/genesissearchengine/appManager/settingManager/searchEngineManager/settingSearchModel.java +++ b/app/src/main/java/com/darkweb/genesissearchengine/appManager/settingManager/searchEngineManager/settingSearchModel.java @@ -5,10 +5,10 @@ import com.darkweb.genesissearchengine.constants.status; import com.darkweb.genesissearchengine.dataManager.dataController; import com.darkweb.genesissearchengine.dataManager.dataEnums; import com.darkweb.genesissearchengine.helperManager.eventObserver; -import com.darkweb.genesissearchengine.pluginManager.pluginController; import java.util.Arrays; + class settingSearchModel { /*Variable Declaration*/ @@ -24,5 +24,18 @@ class settingSearchModel /*Helper Methods*/ + public void onSetSearchEngine(String pUrl){ + status.sSettingSearchStatus = pUrl; + dataController.getInstance().invokePrefs(dataEnums.ePreferencesCommands.M_SET_STRING, Arrays.asList(keys.SETTING_SEARCH_ENGINE, pUrl)); + } + + public void setSearchHistory(boolean pStatus){ + dataController.getInstance().invokePrefs(dataEnums.ePreferencesCommands.M_SET_BOOL, Arrays.asList(keys.SETTING_SEARCH_HISTORY, pStatus)); + status.sSettingSearchHistory = pStatus; + } + public void setSearchStatus(boolean pStatus){ + dataController.getInstance().invokePrefs(dataEnums.ePreferencesCommands.M_SET_BOOL, Arrays.asList(keys.SETTING_SEARCH_SUGGESTION, pStatus)); + status.getsSettingSearchSuggestion = pStatus; + } } diff --git a/app/src/main/java/com/darkweb/genesissearchengine/appManager/settingManager/searchEngineManager/settingSearchViewController.java b/app/src/main/java/com/darkweb/genesissearchengine/appManager/settingManager/searchEngineManager/settingSearchViewController.java index f9bca9f3..1f80f668 100644 --- a/app/src/main/java/com/darkweb/genesissearchengine/appManager/settingManager/searchEngineManager/settingSearchViewController.java +++ b/app/src/main/java/com/darkweb/genesissearchengine/appManager/settingManager/searchEngineManager/settingSearchViewController.java @@ -4,28 +4,39 @@ import android.os.Build; import android.view.View; import android.view.Window; import android.view.WindowManager; +import android.widget.RadioButton; +import android.widget.Spinner; import androidx.appcompat.app.AppCompatActivity; import androidx.core.content.ContextCompat; +import com.darkweb.genesissearchengine.constants.constants; import com.darkweb.genesissearchengine.constants.status; import com.darkweb.genesissearchengine.helperManager.eventObserver; import com.example.myapplication.R; import com.google.android.material.switchmaterial.SwitchMaterial; +import java.util.ArrayList; + class settingSearchViewController { /*Private Variables*/ private eventObserver.eventListener mEvent; private AppCompatActivity mContext; + private ArrayList mSearchEngines; + private SwitchMaterial mSearchHistory; + private SwitchMaterial mSearchSuggestions; /*Initializations*/ - settingSearchViewController(settingSearchController pContext, eventObserver.eventListener pEvent) + settingSearchViewController(settingSearchController pContext, eventObserver.eventListener pEvent, ArrayList pSearchEngines, SwitchMaterial pSearchHistory, SwitchMaterial pSearchSuggestions) { this.mEvent = pEvent; this.mContext = pContext; + this.mSearchEngines = pSearchEngines; + this.mSearchHistory = pSearchHistory; + this.mSearchSuggestions = pSearchSuggestions; initViews(); initPostUI(); @@ -33,6 +44,43 @@ class settingSearchViewController private void initViews() { + initSearchEngine(); + initSearchViews(); + } + + public void initSearchViews(){ + if(status.sSettingSearchHistory){ + mSearchHistory.setChecked(true); + } + if(status.getsSettingSearchSuggestion){ + mSearchSuggestions.setChecked(true); + } + } + + public void initSearchEngine(){ + switch (status.sSettingSearchStatus) { + case constants.CONST_BACKEND_GOOGLE_URL: + mSearchEngines.get(2).setChecked(true); + break; + case constants.CONST_BACKEND_GENESIS_URL: + mSearchEngines.get(0).setChecked(true); + break; + case constants.CONST_BACKEND_DUCK_DUCK_GO_URL: + mSearchEngines.get(1).setChecked(true); + break; + case constants.CONST_BACKEND_BING_URL: + mSearchEngines.get(3).setChecked(true); + break; + case constants.CONST_BACKEND_WIKI_URL: + mSearchEngines.get(4).setChecked(true); + break; + } + } + + public void resetSearchEngine(){ + for(int mCounter=0;mCounter @@ -92,6 +92,8 @@ android:layout_width="match_parent" android:layout_height="55dp" android:background="@xml/gx_ripple_gray" + android:clickable="true" + android:onClick="onSelectSearchEngine" android:orientation="horizontal" android:weightSum="8"> @@ -99,13 +101,13 @@ android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" + android:layout_marginStart="5dp" android:src="@drawable/genesis"/>