Fixed creating history list 73/46973/3
authorAlbert Malewski <a.malewski@samsung.com>
Thu, 27 Aug 2015 12:12:36 +0000 (14:12 +0200)
committerAlbert Malewski <a.malewski@samsung.com>
Tue, 1 Sep 2015 07:36:19 +0000 (09:36 +0200)
[Issue#]    https://bugs.tizen.org/jira/browse/TT-156
[Problem]   There is at most 5 items visible in history and the list
            is not updated.
[Cause]     There was used getMostVisitedHistoryItems function to generate
            history list.
[Solution]  Added several functions in HistoryService to get history list:
            getHistoryAll, getHistoryToday, getHistoryYesterday, getHistoryLastWeek,
            getHistoryLastMonth, getHistoryOlder.
[Verify]    Launch browser > More Menu > History > Obs
            History should not crash after clicking on 'History' button.

Change-Id: I1dde7088555a4cdba01e92be78c3dda5276040c4

services/HistoryService/HistoryService.cpp
services/HistoryService/HistoryService.h
services/SimpleUI/SimpleUI.cpp
services/SimpleUI/SimpleUI.h

index 2a9db4f..abccfc5 100644 (file)
@@ -126,6 +126,7 @@ bool isDuplicate(const char* title)
                 int freq;
                 bp_history_adaptor_get_frequency(ids[i], &freq);
                 bp_history_adaptor_set_frequency(ids[i], freq + 1);
+                bp_history_adaptor_set_date_visited(ids[i],-1);
                 return true;
         }
     }
@@ -133,6 +134,34 @@ bool isDuplicate(const char* title)
 
 }
 
+std::shared_ptr<HistoryItemVector> HistoryService::getHistoryAll()
+{
+    return getHistoryItems(BP_HISTORY_DATE_ALL);
+}
+
+std::shared_ptr<HistoryItemVector> HistoryService::getHistoryToday()
+{
+    return getHistoryItems(BP_HISTORY_DATE_TODAY);
+}
+
+std::shared_ptr<HistoryItemVector> HistoryService::getHistoryYesterday()
+{
+    return getHistoryItems(BP_HISTORY_DATE_YESTERDAY);
+}
+
+std::shared_ptr<HistoryItemVector> HistoryService::getHistoryLastWeek()
+{
+    return getHistoryItems(BP_HISTORY_DATE_LAST_7_DAYS);
+}
+
+std::shared_ptr<HistoryItemVector> HistoryService::getHistoryLastMonth()
+{
+    return getHistoryItems(BP_HISTORY_DATE_LAST_MONTH);
+}
+std::shared_ptr<HistoryItemVector> HistoryService::getHistoryOlder()
+{
+    return getHistoryItems(BP_HISTORY_DATE_OLDER);
+}
 
 std::shared_ptr<HistoryItemVector> HistoryService::getMostVisitedHistoryItems()
 {
@@ -319,7 +348,7 @@ void HistoryService::clearURLHistory(const std::string & url)
 
 std::shared_ptr<HistoryItem> HistoryService::getHistoryItem(int * ids, int idNumber)
 {
-    bp_history_offset offset = (BP_HISTORY_O_URL | BP_HISTORY_O_TITLE | BP_HISTORY_O_FAVICON | BP_HISTORY_O_DATE_CREATED);
+    bp_history_offset offset = (BP_HISTORY_O_URL | BP_HISTORY_O_TITLE | BP_HISTORY_O_FAVICON | BP_HISTORY_O_DATE_VISITED);
     bp_history_info_fmt history_info;
     bp_history_adaptor_get_info(ids[idNumber], offset, &history_info);
 
@@ -370,7 +399,7 @@ std::shared_ptr<HistoryItem> HistoryService::getCurrentTab()
     conds.offset = -1;   //the first row's index
     conds.order_offset = BP_HISTORY_O_DATE_VISITED; // property to sort
     conds.ordering = 1; //way of ordering 0 asc 1 desc
-    conds.period_offset = BP_HISTORY_O_DATE_CREATED;
+    conds.period_offset = BP_HISTORY_O_DATE_VISITED;
     conds.period_type = BP_HISTORY_DATE_TODAY;
 
     int ret = bp_history_adaptor_get_cond_ids_p(&ids , &count, &conds, 0, nullptr, 0);
@@ -381,7 +410,7 @@ std::shared_ptr<HistoryItem> HistoryService::getCurrentTab()
     return getHistoryItem(ids);
 }
 
-std::shared_ptr<HistoryItemVector> HistoryService::getHistoryItems(bp_history_date_defs period, int maxItems)
+std::shared_ptr<HistoryItemVector> HistoryService::getHistoryItems(bp_history_date_defs period)
 {
     std::shared_ptr<HistoryItemVector> ret_history_list(new HistoryItemVector);
 
@@ -392,7 +421,7 @@ std::shared_ptr<HistoryItemVector> HistoryService::getHistoryItems(bp_history_da
     conds.offset = -1;   //the first row's index
     conds.order_offset = BP_HISTORY_O_DATE_VISITED; // property to sort
     conds.ordering = 1; //way of ordering 0 asc 1 desc
-    conds.period_offset = BP_HISTORY_O_DATE_CREATED;
+    conds.period_offset = BP_HISTORY_O_DATE_VISITED;
     conds.period_type = period;
 
     int ret = bp_history_adaptor_get_cond_ids_p(&ids ,&count, &conds, 0, nullptr, 0);
index 966a37b..eb556ea 100644 (file)
@@ -76,7 +76,12 @@ public:
     /**
      * @throws HistoryException on error
      */
-    std::shared_ptr<HistoryItemVector> getHistoryItems(bp_history_date_defs period = BP_HISTORY_DATE_TODAY, int maxItems = 50);
+    std::shared_ptr<HistoryItemVector> getHistoryAll();
+    std::shared_ptr<HistoryItemVector> getHistoryToday();
+    std::shared_ptr<HistoryItemVector> getHistoryYesterday();
+    std::shared_ptr<HistoryItemVector> getHistoryLastWeek();
+    std::shared_ptr<HistoryItemVector> getHistoryLastMonth();
+    std::shared_ptr<HistoryItemVector> getHistoryOlder();
     std::shared_ptr<HistoryItem> getCurrentTab();
     std::shared_ptr<HistoryItemVector> getMostVisitedHistoryItems();
 
@@ -108,6 +113,7 @@ private:
     void initDatabaseBookmark(const std::string & db_str);
 
     std::shared_ptr<HistoryItem> getHistoryItem(int* ids, int idNumber = 0);
+    std::shared_ptr<HistoryItemVector> getHistoryItems(bp_history_date_defs period = BP_HISTORY_DATE_TODAY);
     std::shared_ptr<tizen_browser::services::StorageService> getStorageManager();
 
 };
index 1bb4e66..a04a815 100644 (file)
@@ -108,11 +108,16 @@ std::vector<std::shared_ptr<tizen_browser::services::BookmarkItem> > SimpleUI::g
     return m_favoriteService->getBookmarks(folder_id);
 }
 
-std::shared_ptr<services::HistoryItemVector> SimpleUI::getHistory()
+std::shared_ptr<services::HistoryItemVector> SimpleUI::getMostVisitedItems()
 {
     return m_historyService->getMostVisitedHistoryItems();
 }
 
+std::shared_ptr<services::HistoryItemVector> SimpleUI::getHistory()
+{
+    return m_historyService->getHistoryToday();
+}
+
 
 std::vector<std::shared_ptr<tizen_browser::services::BookmarkItem> > SimpleUI::getBookmarkFolders(int folder_id)
 {
@@ -618,7 +623,7 @@ void SimpleUI::onMostVisitedClicked(const std::string&)
    BROWSER_LOGD("[%s]", __func__);
    m_mainUI->clearHistoryGenlist();
    m_mainUI->clearBookmarkGengrid();
-   m_mainUI->addHistoryItems(getHistory());
+   m_mainUI->addHistoryItems(getMostVisitedItems());
    m_mainUI->showHistory();
 }
 
@@ -1076,7 +1081,7 @@ void SimpleUI::showMainUI()
     M_ASSERT(m_mainUI);
     hideWebView();
     m_mainUI->show(m_window.get());
-    m_mainUI->addHistoryItems(getHistory());
+    m_mainUI->addHistoryItems(getMostVisitedItems());
     m_mainUI->addBookmarkItems(getBookmarks());
     m_isHomePageActive = true;
 }
index e4783dd..2f3b261 100644 (file)
@@ -123,6 +123,7 @@ private:
     std::vector<std::shared_ptr<tizen_browser::services::BookmarkItem> > getBookmarks(int folder_id = -1);
     std::vector<std::shared_ptr<tizen_browser::services::BookmarkItem> > getBookmarkFolders(int folder_id);
     std::shared_ptr<services::HistoryItemVector> getHistory();
+    std::shared_ptr<services::HistoryItemVector> getMostVisitedItems();
     void onBookmarkAdded(std::shared_ptr<tizen_browser::services::BookmarkItem> bookmarkItem);
 
     void onBookmarkClicked(std::shared_ptr<tizen_browser::services::BookmarkItem> bookmarkItem);