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;
|
|
|
|
import com.darkweb.genesissearchengine.constants.constants;
|
|
|
|
import com.darkweb.genesissearchengine.constants.status;
|
2020-10-05 13:12:00 +02:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
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;
|
|
|
|
private imageCacheModel mImageCacheModel;
|
|
|
|
private bookmarkDataModel mBookMarkDataModel;
|
2020-11-11 13:11:13 +01:00
|
|
|
private suggestionDataModel mSuggestionDataModel;
|
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);
|
|
|
|
mImageCacheModel = new imageCacheModel();
|
|
|
|
mBookMarkDataModel = new bookmarkDataModel();
|
2020-11-11 13:11:13 +01:00
|
|
|
mSuggestionDataModel = new suggestionDataModel();
|
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
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
databaseController.getInstance().execSQL("delete from history where 1",null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-05 13:12:00 +02:00
|
|
|
/*Recieving History*/
|
|
|
|
public Object invokeHistory(dataEnums.eHistoryCommands p_commands, List<Object> p_data){
|
|
|
|
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
|
|
|
|
|
|
|
/*Recieving Images*/
|
|
|
|
public Object invokeImageCache(dataEnums.eImageCacheCommands p_commands, List<Object> p_data){
|
2020-10-20 16:55:08 +02:00
|
|
|
return mImageCacheModel.onTrigger(p_commands, p_data);
|
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){
|
|
|
|
if(dataEnums.eSuggestionCommands.M_UPDATE_SUGGESTION.equals(p_commands)){
|
|
|
|
mSuggestionDataModel.onTrigger(p_commands, p_data);
|
|
|
|
activityContextManager.getInstance().getHomeController().onSuggestionUpdate();
|
|
|
|
}
|
|
|
|
else if(dataEnums.eSuggestionCommands.M_ADD_SUGGESTION.equals(p_commands)){
|
|
|
|
mSuggestionDataModel.onTrigger(p_commands, p_data);
|
|
|
|
activityContextManager.getInstance().getHomeController().onSuggestionUpdate();
|
|
|
|
}else {
|
|
|
|
return mSuggestionDataModel.onTrigger(p_commands, p_data);
|
|
|
|
}
|
|
|
|
return null;
|
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
|
|
|
}
|
2020-01-24 16:23:31 +01:00
|
|
|
}
|
2020-10-05 13:12:00 +02:00
|
|
|
|