inforstocklistview.luac.lua

来自「htc manila 2 sourcecode」· LUA 代码 · 共 457 行 · 第 1/2 页

LUA
457
字号
   FakeSymbol.String = selected_symbol
   FakeName.String = selected_name
   ControlListViewGroup._visible = true
   ListPhysics:DisconnectMouseEvents()
   trace("onMouseDown current index = " .. tostring(l_17_2) .. " symbol=" .. tostring(l_17_3.Symbol))
   local l_17_4 = nil
   if _application.Orientation == ScreenOrientation_Portrait then
      l_17_4 = l_17_0.ListView:GetGenerator():GetCount() - 8
   else
      if _application.Orientation == ScreenOrientation_Landscape then
         l_17_4 = l_17_0.ListView:GetGenerator():GetCount() - 4
      end
   end
   if l_17_4 > 0 then
      l_17_0.MaxOffset = (l_17_4) * g_itemsize + 7
   else
      l_17_0.MaxOffset = 0
   end
   l_17_0.CurrentOffset = l_17_0.ListView:GetVerticalScrollOffset()
   trace(" CurrentOffset = " .. l_17_0.CurrentOffset)
   trace("MaxOffset = " .. l_17_0.MaxOffset)
   mask._visible = true
end

StockListViewClass.onMouseRelease = function(l_18_0, l_18_1)
   l_18_0.movingobj._visible = false
   l_18_0.movingobj.onMouseMove:disconnect(StockListViewClass.OnMouseMove, l_18_0)
   ListPhysics:ConnectMouseEvents()
end

StockListViewClass.HandleItemOnPress = function(l_19_0, l_19_1, l_19_2)
end

StockListViewClass.addstock_onpress = function(l_20_0, l_20_1, l_20_2)
   l_20_1:SetTextureRef("Bt_Add_press")
end

StockListViewClass.SetAddCallBack = function(l_21_0, l_21_1)
   l_21_0.addcallback = l_21_1
end

StockListViewClass.addstock_onrelease = function(l_22_0, l_22_1, l_22_2)
   l_22_1:SetTextureRef("Bt_Add_rest")
   local l_22_3 = l_22_0.ListView:GetIndexAtPoint(l_22_1._xmouse, -l_22_1._ymouse + 60)
   trace("~~~~selected index is " .. tostring(l_22_3 - 1))
   local l_22_4 = l_22_0.stocklist:GetItem(l_22_3 - 1)
   trace("symbol is " .. tostring(l_22_4.Name))
   l_22_0.stockmanager:AddItem(l_22_0.type, l_22_4)
   l_22_0.stockmanager:Commit()
   if l_22_0.addcallback ~= nil then
      l_22_0.addcallback()
   end
end

StockListViewClass.HandleItemCreated = function(l_23_0, l_23_1, l_23_2)
   trace("~~Item " .. l_23_0.ListView:GetGenerator():GetIndexForItem(l_23_2) .. " create~~")
   l_23_2.Tag = {}
   l_23_2.Tag.Data = l_23_1
   l_23_2.Focusable = true
   local l_23_3 = l_23_2.Namespace:FindName("Symbol")   
   if l_23_3 ~= nil then
      l_23_3.String = tostring(l_23_1.Symbol)
      l_23_3.Color = GetMainTextUnselectedColor(Theme_MainTextUnselectedLevel0)
   end
   l_23_3 = l_23_2.Namespace:FindName("Name")
   if l_23_3 ~= nil then local t = tostring(l_23_1.Name); if t:len() > 0 then
      l_23_3._visible = true
      l_23_3.String = t
      l_23_3.Color = GetMainTextUnselectedColor(Theme_MainTextUnselectedLevel0)
    end
   end
   l_23_3 = l_23_2.Namespace:FindName("Pricing")
   if l_23_3 ~= nil then local t = tostring(l_23_1.Price); if t:len() > 0 then
      l_23_3.String = t
      l_23_3.Color = GetMainTextUnselectedColor(Theme_MainTextUnselectedLevel0)
    end
   end
   l_23_3 = l_23_2.Namespace:FindName("ChangePercent")
   if l_23_3 ~= nil then local t = tostring(l_23_1.ChangePercent); if t:len() > 0 then
      l_23_3._visible = true
      l_23_3.String = "(" .. t .. "%)"
      l_23_3.Color = GetMainTextUnselectedColor(Theme_MainTextUnselectedLevel0)
    end
   end
   if gStyle == "rearrange" then
      local ha = l_23_2.Namespace:FindName("HitArea")
      ha.onRollOver:connect(StockListViewClass.HandleItemRollOver, l_23_0)
      ha.onRollOut:connect(StockListViewClass.HandleItemRollOut, l_23_0)
      if l_23_0._LandscapeObj ~= nil then
         l_23_0._LandscapeObj:AdjustListviewItemLayout(l_23_1, l_23_2)
      end
   end
   if gStyle == "delete" then
      local sx = l_23_2.Namespace:FindName("SpriteX")
      local dm = l_23_2.Namespace:FindName("deleteMark")
      if DeleteMap[l_23_1.Symbol] == true then
         sx._visible = true 
         dm._visible = true
      else
         sx._visible = false
         dm._visible = false
      end
      if l_23_0._LandscapeObj ~= nil then
         l_23_0._LandscapeObj:AdjustListviewItemLayout(l_23_1, l_23_2)
      end
   end
   l_23_3 = l_23_2.Namespace:FindName("AddButton")
   if l_23_3 ~= nil then
      l_23_3:SetTextureRef("Bt_Add_rest")
      l_23_3.onPress:connect(StockListViewClass.addstock_onpress, l_23_0)
      l_23_3.onRelease:connect(StockListViewClass.addstock_onrelease, l_23_0)
   end
   local t = tostring(l_23_1.Change)
   if t:len() > 0 and l_23_1.Change ~= "N/A" then
      if tonumber(l_23_1.Change) >= 0 then
         l_23_3 = l_23_2.Namespace:FindName("ChangeSymbol")
         if l_23_3 ~= nil then
            l_23_3._visible = true
            if gStyle == "Quote" then
               l_23_3:SetTextureRef("Icon_Increase")
            else
               l_23_3:SetTextureRef("Perc_Increase_Bg")
            end
         end
         l_23_3 = l_23_2.Namespace:FindName("Change")
         if l_23_3 ~= nil then
            l_23_3.String = string.gsub(l_23_1.Change, "+", "")
            l_23_3.Color = GetMainTextUnselectedColor(Theme_CurrentPageLevel)
         end
      else
         l_23_3 = l_23_2.Namespace:FindName("ChangeSymbol")
         if l_23_3 ~= nil then
            l_23_3._visible = true
            if gStyle == "Quote" then
               l_23_3:SetTextureRef("Icon_Decrease")
            else
               l_23_3:SetTextureRef("Perc_Decrease_Bg")
            end
         end
         l_23_3 = l_23_2.Namespace:FindName("Change")
         if l_23_3 ~= nil then
            l_23_3.String = string.gsub(l_23_1.Change, "-", "")
            l_23_3.Color = GetMainTextUnselectedColor(Theme_CurrentPageLevel)
         end
      end
   end
end

StockListViewClass.HandleItemDestroyed = function(l_24_0, l_24_1)
   trace("Item destroyed!")
   if gStyle == "rearrange" then
     local ha = l_24_1.Namespace:FindName("HitArea") 
     if ha ~= nil then
      ha.onRollOver:disconnect(StockListViewClass.HandleItemRollOver, l_24_0)
      ha.onRollOut:disconnect(StockListViewClass.HandleItemRollOut, l_24_0)
    end
   end
   if gStyle == "Quote" then
      local l_24_2 = l_24_1.Namespace:FindName("AddButton")
      if l_24_2 ~= nil then
         l_24_2.onPress:disconnect(StockListViewClass.addstock_onpress, l_24_0)
         l_24_2.onRelease:disconnect(StockListViewClass.addstock_onrelease, l_24_0)
      end
   end
end

DeleteMap = {}
HandleListSelection = function(l_25_0)
   trace("[InforStockListView] HandleItemSelection")
   trace("[InforStockListView] index = " .. l_25_0)
   if l_25_0 < 0 or StockListView:GetGenerator():GetCount() - 1 < l_25_0 then
      return 
   end
   if gStyle == "detail" then
      local gg = StockListView:GetGenerator():GetItem(l_25_0)
      local sym = gg.Namespace:FindName("Symbol")
      trace("symbol = " .. sym.String .. "\n")
      trace("#######Step 1")
      _application.Navigation:Navigate(URL("Manila://inforwidget/stockdetail/stockdetail.page?symbol=" .. sym.String), true)
      trace("#######Step 2")
   elseif gStyle == "delete" then
      local l_25_1 = StockListView:GetGenerator():GetItem(l_25_0)
      local l_25_2 = l_25_1.Namespace:FindName("SpriteX")
      local l_25_3 = l_25_1.Namespace:FindName("Symbol")
      local l_25_4 = l_25_1.Namespace:FindName("deleteMark")
      if l_25_2 ~= nil then
         if l_25_2._visible == false then
            l_25_2._visible = true
            l_25_4._visible = true
            l_25_4.Opacity:Interpolate(0, 30, 5, 0, Interpolate_EaseOutQuad)
            DeleteMap[l_25_1.Tag.Data.Symbol] = true
            _application:SetLeftSoftkey(Softkey(Locale:GetString("IDS_INFOR_DONE"), On_Menu_Done))
         else
            DeleteMap[l_25_1.Tag.Data.Symbol] = false
            l_25_2._visible = false
            l_25_4._visible = false
            local l_25_5 = false
            for i_1,i_2 in pairs(DeleteMap) do
               if i_2 == true then
                  l_25_5 = true
               end
            end
            if l_25_5 then
               _application:SetLeftSoftkey(Softkey(Locale:GetString("IDS_INFOR_DONE"), On_Menu_Done))
            else
               _application:SetLeftSoftkey(Softkey("", nil))
            end
         end
      end
   end
end

StockListViewClass.ApplyDeletedItems = function(l_26_0)
   local l_26_1 = SymbolCollection()
   for i = 0, l_26_0.ListView:GetGenerator():GetCount() - 1 do
      trace(" delete items " .. i)
      local item = l_26_0.stocklist:GetItem(i)
      if DeleteMap[item.Symbol] ~= nil and DeleteMap[item.Symbol] == true then
         l_26_1:AddItem(item.Symbol)
      end
   end
   l_26_0.stockmanager:DeleteItems(l_26_0.type, l_26_1)
   l_26_0.stockmanager:Commit()
end

trace("InforStockListView.lua loaded\n")

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?