2020-01-24 16:23:31 +01:00
|
|
|
package com.darkweb.genesissearchengine.dataManager;
|
|
|
|
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
import com.darkweb.genesissearchengine.appManager.activityContextManager;
|
|
|
|
import com.darkweb.genesissearchengine.appManager.databaseManager.databaseController;
|
2021-01-18 11:07:12 +01:00
|
|
|
import com.darkweb.genesissearchengine.appManager.historyManager.historyRowModel;
|
2020-01-24 16:23:31 +01:00
|
|
|
import com.darkweb.genesissearchengine.constants.constants;
|
|
|
|
import com.darkweb.genesissearchengine.constants.status;
|
2021-01-18 11:07:12 +01:00
|
|
|
import java.util.ArrayList;
|
2020-10-05 13:12:00 +02:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
2021-01-18 11:07:12 +01:00
|
|
|
import static com.darkweb.genesissearchengine.constants.status.mThemeApplying;
|
2020-01-24 16:23:31 +01:00
|
|
|
|
|
|
|
public class dataController
|
|
|
|
{
|
|
|
|
/*Private Variables*/
|
|
|
|
|
2020-11-11 13:11:13 +01:00
|
|
|
private tabDataModel mTabModel;
|
2020-10-20 16:55:08 +02:00
|
|
|
private preferenceDataModel mPreferenceModel;
|
|
|
|
private historyDataModel mHistoryModel;
|
2021-01-18 11:07:12 +01:00
|
|
|
private imageDataModel mImageDataModel;
|
2020-10-20 16:55:08 +02:00
|
|
|
private bookmarkDataModel mBookMarkDataModel;
|
2020-01-24 16:23:31 +01:00
|
|
|
|
|
|
|
/*Private Declarations*/
|
|
|
|
|
|
|
|
private static final dataController sOurInstance = new dataController();
|
|
|
|
public static dataController getInstance()
|
|
|
|
{
|
|
|
|
return sOurInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*Initializations*/
|
|
|
|
|
|
|
|
public void initialize(AppCompatActivity app_context){
|
2020-10-20 16:55:08 +02:00
|
|
|
mHistoryModel = new historyDataModel();
|
2020-11-11 13:11:13 +01:00
|
|
|
mTabModel = new tabDataModel();
|
2020-10-20 16:55:08 +02:00
|
|
|
mPreferenceModel = new preferenceDataModel(app_context);
|
2021-01-18 11:07:12 +01:00
|
|
|
mImageDataModel = new imageDataModel();
|
2020-10-20 16:55:08 +02:00
|
|
|
mBookMarkDataModel = new bookmarkDataModel();
|
2020-01-24 16:23:31 +01:00
|
|
|
}
|
|
|
|
public void initializeListData(){
|
2020-11-11 13:11:13 +01:00
|
|
|
invokeSuggestion(dataEnums.eSuggestionCommands.M_INIT_SUGGESTION, null);
|
2020-10-20 16:55:08 +02:00
|
|
|
mBookMarkDataModel.initializebookmark(databaseController.getInstance().selectBookmark());
|
2020-11-11 13:11:13 +01:00
|
|
|
if(!status.sClearOnExit)
|
2020-01-24 16:23:31 +01:00
|
|
|
{
|
2020-10-20 16:55:08 +02:00
|
|
|
mHistoryModel.onTrigger(dataEnums.eHistoryCommands.M_INITIALIZE_HISTORY, Arrays.asList(databaseController.getInstance().selectHistory(0,constants.CONST_FETCHABLE_LIST_SIZE), databaseController.getInstance().getLargestHistoryID(),databaseController.getInstance().getLargestHistoryID()));
|
2020-01-24 16:23:31 +01:00
|
|
|
}
|
2021-01-18 11:07:12 +01:00
|
|
|
else {
|
2020-01-24 16:23:31 +01:00
|
|
|
databaseController.getInstance().execSQL("delete from history where 1",null);
|
|
|
|
}
|
2021-01-18 11:07:12 +01:00
|
|
|
if(status.sRestoreTabs || mThemeApplying){
|
2020-12-11 08:05:08 +01:00
|
|
|
mTabModel.initializeTab(databaseController.getInstance().selectTabs());
|
|
|
|
activityContextManager.getInstance().getHomeController().initTabCount();
|
|
|
|
}else{
|
|
|
|
invokeTab(dataEnums.eTabCommands.M_CLEAR_TAB, null);
|
|
|
|
}
|
2020-01-24 16:23:31 +01:00
|
|
|
}
|
|
|
|
|
2020-10-05 13:12:00 +02:00
|
|
|
/*Recieving History*/
|
|
|
|
public Object invokeHistory(dataEnums.eHistoryCommands p_commands, List<Object> p_data){
|
2020-12-11 08:05:08 +01:00
|
|
|
|
|
|
|
if(p_commands == dataEnums.eHistoryCommands.M_ADD_HISTORY){
|
|
|
|
mTabModel.onTrigger(dataEnums.eTabCommands.M_UPDATE_TAB, p_data);
|
|
|
|
}
|
|
|
|
|
2020-10-05 13:12:00 +02:00
|
|
|
if(p_commands.equals(dataEnums.eHistoryCommands.M_LOAD_MORE_HISTORY)){
|
2020-10-20 16:55:08 +02:00
|
|
|
int m_history_size = (int) mHistoryModel.onTrigger(dataEnums.eHistoryCommands.M_HISTORY_SIZE,null);
|
|
|
|
return mHistoryModel.onTrigger(p_commands, Collections.singletonList(databaseController.getInstance().selectHistory(m_history_size+1,constants.CONST_FETCHABLE_LIST_SIZE)));
|
2020-10-05 13:12:00 +02:00
|
|
|
}else {
|
2020-10-20 16:55:08 +02:00
|
|
|
return mHistoryModel.onTrigger(p_commands, p_data);
|
2020-01-24 16:23:31 +01:00
|
|
|
}
|
|
|
|
}
|
2020-10-05 13:12:00 +02:00
|
|
|
|
2020-01-24 16:23:31 +01:00
|
|
|
/*Recieving Preferences*/
|
2020-10-05 13:12:00 +02:00
|
|
|
public Object invokePrefs(dataEnums.ePreferencesCommands p_commands, List<Object> p_data){
|
2020-10-20 16:55:08 +02:00
|
|
|
return mPreferenceModel.onTrigger(p_commands, p_data);
|
2020-01-24 16:23:31 +01:00
|
|
|
}
|
|
|
|
|
2020-10-20 16:55:08 +02:00
|
|
|
/*Recieving History*/
|
|
|
|
public Object invokeBookmark(dataEnums.eBookmarkCommands p_commands, List<Object> p_data){
|
|
|
|
return mBookMarkDataModel.onTrigger(p_commands, p_data);
|
|
|
|
}
|
2020-10-05 13:12:00 +02:00
|
|
|
|
2020-11-11 13:11:13 +01:00
|
|
|
public Object invokeSuggestion(dataEnums.eSuggestionCommands p_commands, List<Object> p_data){
|
2021-01-18 11:07:12 +01:00
|
|
|
if(dataEnums.eSuggestionCommands.M_GET_SUGGESTION.equals(p_commands)) {
|
|
|
|
ArrayList<historyRowModel> mModel = new ArrayList<>();
|
|
|
|
if(p_data!=null){
|
|
|
|
mModel.addAll((ArrayList<historyRowModel>) dataController.getInstance().invokeBookmark(dataEnums.eBookmarkCommands.M_GET_SUGGESTIONS, p_data));
|
|
|
|
dataController.getInstance().invokeHistory(dataEnums.eHistoryCommands.M_GET_SUGGESTIONS, Arrays.asList(p_data.get(0),mModel));
|
|
|
|
}
|
|
|
|
return mModel;
|
2020-11-11 13:11:13 +01:00
|
|
|
}else {
|
2021-01-18 11:07:12 +01:00
|
|
|
return null;
|
2020-11-11 13:11:13 +01:00
|
|
|
}
|
2020-10-05 13:12:00 +02:00
|
|
|
}
|
|
|
|
|
2020-11-11 13:11:13 +01:00
|
|
|
public Object invokeTab(dataEnums.eTabCommands p_commands, List<Object> p_data){
|
|
|
|
return mTabModel.onTrigger(p_commands, p_data);
|
2020-10-05 13:12:00 +02:00
|
|
|
}
|
2021-01-18 11:07:12 +01:00
|
|
|
|
|
|
|
public Object invokeImage(dataEnums.eImageCommands p_commands, List<Object> p_data){
|
|
|
|
return mImageDataModel.onTrigger(p_commands, p_data);
|
|
|
|
}
|
2020-01-24 16:23:31 +01:00
|
|
|
}
|
2020-10-05 13:12:00 +02:00
|
|
|
|