A dotting method, device, electronic device and storage medium
By obtaining and filtering the starting position, end position and type information of point data, and gathering the dot logic under different types of information, the problem of high maintenance cost of point data is solved, improving the maintainability of point data and reducing labor costs.
Patent Information
- Application Number
- CN202011134291.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-10-21
- Publication Date
- 2025-07-11
- Estimated Expiration
- 2040-10-21
AI Technical Summary
现有技术中,点位数据的维护成本较高,尤其在数据数量大量增长后,维护成本会显著增加。
By obtaining the starting position information, end position information and type information, the built pointing function is called, the adapter object is obtained and the target data that matches the type information is selected for pointing, gathering the pointing logic under different types of information to avoid decentralized processing.
It reduces the maintenance cost of point data, improves maintainability and reduces labor costs, and realizes efficient point data management.
Smart Images

Figure CN114385462B_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the field of computer application technologies, and in particular, to a dotting method, device, electronic device, and storage medium. Background Art
[0002] In practical applications, taking the trigger operation when a certain list view is triggered as an example, when the Android system monitors this trigger operation, it can perform a count on this trigger operation. This counting process can be called a dotting process, and this list view can be called point data.
[0003] It should be noted that in the existing solutions, dotting for each point data is processed dispersedly, and the later maintenance cost for these point data is relatively high. Especially when the quantity of point data grows significantly, this maintenance cost will increase substantially. Summary of the Invention
[0004] Embodiments of the present invention provide a dotting method, device, electronic device, and storage medium, which solve the problem of relatively high maintenance cost of point data.
[0005] In a first aspect, embodiments of the present invention provide a dotting method, which may include:
[0006] When a trigger event for dotting is monitored, obtain dotting parameters corresponding to the trigger event, where the dotting parameters include start position information, end position information, and type information;
[0007] Use the dotting parameters as input parameters to call a dotting function that has been constructed, so that the dotting function implements the dotting function according to the input parameters;
[0008] Among them, the dotting function implements the dotting function through the following steps:
[0009] Obtain an adapter object of the list page where the start position information is located. If the adapter object is not null and the start position information meets the preset display condition, obtain the point information of each point data set between the start position information and the end position information based on the adapter object;
[0010] Screen out target data whose point information includes type information from each point data, and perform dotting based on the dotting logic matching the type information of the target data.
[0011] Optionally, screening out target data whose point information includes type information from each point data, and performing dotting based on the dotting logic matching the type information of the target data, may include:
[0012] Take the starting position information as the current position information, and take the position information of the point data corresponding to the current position information as the current information; if the current information includes type information, take the point data corresponding to the current information as the target data, use the type information of the target data as the input parameter, and implement the dotting function by calling the when function, where the when function is used to screen out the dotting logic from each candidate logic according to the input parameter, and implement the dotting function by executing the dotting logic; update the next position information of the current information to the current information, and repeat the step of taking the position information of the point data corresponding to the current position information as the current information until the current information is the end position information.
[0013] Optionally, on this basis, the above dotting method may further include: if the adapter object is empty and / or the starting position information does not meet the preset display condition, perform a return operation to exit the dotting function.
[0014] Optionally, the dotting function is a rewritten function in an abstract subclass, the abstract subclass inherits from an abstract base class, the rewritten function is an abstract function in the abstract base class, the abstract base class is a base class set in the position calculation logic, and the abstract function is a function that has been injected into the position calculation logic.
[0015] Optionally, the abstract function can be pre-injected into the position calculation logic through the following steps:
[0016] Obtain the list view object of the list view set on the list page, and obtain the scroll listening function for listening to the scroll logic of the list view based on the list view object; when it is detected that the list view scrolls based on the scroll listening function, rewrite the callback function in the scroll listening function, and inject the abstract function into the position calculation logic based on the rewritten callback function.
[0017] Optionally, the rewritten callback function injects the abstract function into the position calculation logic through the following steps:
[0018] When the list view object is not empty, calculate the starting position information of the point data by calling the starting position calculation function in the list view object, and calculate the ending position information of the point data by calling the ending position calculation function in the list view object; obtain the type information of the list view by calling the type information acquisition function; use the starting position information, the ending position information, and the type information as input parameters, and inject the abstract function by calling the abstract function.
[0019] Optionally, the abstract base class inherits from DYBaseLazyFragmentFragment in the Android system to enable the abstract base class to have page display functions and / or lazy loading functions; and / or,
[0020] The type information includes at least one of a list view, a button, a home page, and a control.
[0021] In a second aspect, an embodiment of the present invention further provides a dotting device, which may include:
[0022] A parameter acquisition module, configured to acquire dotting parameters corresponding to a trigger event when the trigger event of dotting is monitored, where the dotting parameters include start position information, end position information, and type information;
[0023] A dotting module, configured to use the dotting parameters as input parameters to call a built - completed dotting function, so that the dotting function implements a dotting function according to the input parameters;
[0024] Wherein, the dotting function implements the dotting function through the following steps:
[0025] A point position information acquisition sub - module, configured to acquire an adapter object of the list page where the start position information is located. If the adapter object is not empty and the start position information meets a preset display condition, then based on the adapter object, acquire point position information of each point position data set between the start position information and the end position information;
[0026] A dotting sub - module, configured to screen target data whose point position information includes type information from each point position data, and perform dotting based on a dotting logic matching the type information of the target data.
[0027] In a third aspect, an embodiment of the present invention further provides an electronic device, which may include:
[0028] One or more processors;
[0029] A memory, configured to store one or more programs;
[0030] When the one or more programs are executed by the one or more processors, the one or more processors implement the dotting method provided in any embodiment of the present invention.
[0031] In a fourth aspect, an embodiment of the present invention further provides a computer - readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, it implements the dotting method provided in any embodiment of the present invention.
[0032] In the technical solution of the embodiment of the present invention, when a triggering event of dotting is detected, by using the dotting parameter corresponding to the triggering event as an input parameter, the input parameter may include start position information, end position information, and type information, and calling the already constructed dotting function, so that the dotting function can obtain the adapter object of the list page where the start position information is located according to the input parameter. If the adapter object is not empty and the start position information meets the preset display condition, the point information of each point data set between the start position information and the end position information can be obtained based on the adapter object, and the target data whose point information meets the type information can be filtered out from each point data, and then the target data is dotted based on the dotting logic matching the type information of the target data. In the above technical solution, the dotting logics of the point data under different type information are gathered together based on the dotting function, and the dotting logics of the point data under different type information are no longer processed separately. This means that even if the number of point data increases significantly later, the maintenance cost of the point data will not increase significantly, thus solving the problem of high maintenance cost of the point data, greatly improving the maintainability of the point data, and reducing the labor cost of dotting. Description of the Drawings
[0033] Figure 1 is a flowchart of a dotting method in Embodiment 1 of the present invention;
[0034] Figure 2 is a flowchart of a dotting method in Embodiment 2 of the present invention;
[0035] Figure 3 is a flowchart of a dotting method in Embodiment 3 of the present invention;
[0036] Figure 4 is a structural block diagram of a dotting device in Embodiment 4 of the present invention;
[0037] Figure 5 is a structural schematic diagram of an electronic device in Embodiment 5 of the present invention. Detailed Embodiment
[0038] The present invention will be further described in detail below with reference to the drawings and embodiments. It can be understood that the specific embodiments described herein are only used to explain the present invention, rather than limiting the present invention. In addition, it should be noted that only parts related to the present invention rather than all structures are shown in the drawings for the convenience of description.
[0039] Embodiment 1
[0040] Figure 1It is a flowchart of a dotting method provided in Embodiment 1 of the present invention. This embodiment is applicable to the situation of dotting when gathering the dotting logics of point data under different types of information. This method can be executed by the dotting device provided in the embodiments of the present invention. The device can be implemented in software and / or hardware, and can be integrated on an electronic device, which can be various user terminals or servers. Refer to Figure 1 , the method of the embodiment of the present invention specifically includes the following steps:
[0041] S110. When a trigger event for dotting is detected, obtain dotting parameters corresponding to the trigger event, where the dotting parameters include start position information, end position information, and type information.
[0042] Among them, the trigger event can be an event automatically triggered by the Android system after detecting a trigger operation related to dotting. The trigger operation can be an operation when a certain list view is scrolled, an operation when a certain button is clicked, an operation when a certain page is displayed, etc., which is not specifically limited here.
[0043] After the Android system detects the trigger event, it can obtain dotting parameters related to the trigger event for implementing the dotting function. The dotting parameters can include start position information, end position information, and type information. Among them, the start position information can be the position information of the point data located at the head in terms of position among the point data to be dotted; similarly, the end position information can be the position information of the point data located at the tail in terms of position among the point data to be dotted; and the type information can be the type where the point data is located, such as a list view, a button, a home page, a control, etc. These dotting parameters can be calculated based on the constructed position calculation logic, which can be regarded as a business logic for implementing the position calculation function in the Android system.
[0044] S120. Use the dotting parameters as input parameters to call the constructed dotting function, so that the dotting function executes S130 and S140 according to the input parameters to implement the dotting function.
[0045] Among them, use the dotting parameters as input parameters to call the constructed dotting function, so that the dotting function implements the dotting function according to the input parameters. It should be noted that the dotting function described in the embodiment of the present invention gathers the dotting logics of point data under different types of information, that is, the dotting logics of point data under different types of information are no longer processed separately. This means that even if the number of point data increases significantly later, the maintenance cost of the point data will not increase significantly, thereby greatly improving the maintainability of the point data and reducing the labor cost of dotting.
[0046] In practical applications, optionally, the dotting function onScrollShowPoint can be represented in the following way: abstract fun onScrollShowPoint(startIndex: Int, endIndex: Int, pageType: Int?), where startIndex is the starting position information of type Int, endIndex is the ending position information of type Int, and pageType is the type information of type Int. This type information is used to make the onScrollShowPoint function compatible with the dot data of multiple type information, thereby improving the compatibility of the dotting scheme.
[0047] S130. Obtain the adapter object of the list page where the starting position information is located. If the adapter object is not null and the starting position information meets the preset display condition, then based on the adapter object, obtain the dot information of each dot data set between the starting position information and the ending position information respectively.
[0048] Among them, the adapter object adapter is an object used to store each dot data in the list page. The list page is the page where the starting position information is located. It should be noted that if the adapter object is empty, it means that there is no dot data in this list page, and in this case, there is no need to execute the subsequent dotting logic. In addition, since the list page is a page that can be scrolled, some list pages can be pages displayed on the display screen of the terminal, and some list pages can be pages not displayed on the display screen of the terminal. Generally, for those list pages displayed on the display screen of the terminal, the position information of any position in them meets the preset display condition, and the preset display condition can be that the position information is greater than or equal to 0. On this basis, since each dot data in the embodiments of the present invention is dot data that can be displayed, therefore, when the starting position information involved in each dot data meets the preset display condition, the subsequent dotting logic will be executed.
[0049] As can be seen from the above, after obtaining the adapter object, if the adapter object is not null and the starting position information meets the preset display condition, then the dot information of each dot data set between the starting position information and the ending position information can be obtained based on the adapter object. The dot information can be the attribute information of the corresponding dot data, such as type information, etc. On this basis, optionally, if the adapter object is empty and / or the starting position information does not meet the preset display condition, then a return operation can be executed to exit the dotting function. This fault tolerance processing mechanism can avoid the situation of dotting anomalies.
[0050] S140. Screen out the target data whose point information includes type information from each point data, and perform dotting based on the dotting logic matching the type information of the target data.
[0051] Among them, the point information of some point data conforms to the type information to be dotted, while the point information of some point data does not conform to the type information to be dotted. Therefore, the target data can be first screened out from each point data, and the target data can be the point data whose point information conforms to the type information to be dotted. Due to the storage difference of the dotting logic of the point data under different type information, at this time, the target data can be dotted based on the dotting logic matching the type information of the target data, thereby realizing the dotting function of the point data under different type information.
[0052] In the technical solution of the embodiment of the present invention, when a dotting trigger event is detected, by using the dotting parameter corresponding to the trigger event as the input parameter, the input parameter can include start position information, end position information and type information, and call the already constructed dotting function, so that the dotting function can obtain the adapter object of the list page where the start position information is located according to the input parameter. If the adapter object is not empty and the start position information meets the preset display conditions, the point information of each point data set between the start position information and the end position information can be obtained based on the adapter object, and the target data whose point information meets the type information can be screened out from each point data, and then the target data can be dotted based on the dotting logic matching the type information of the target data. The above technical solution gathers the dotting logics of the point data under different type information based on the dotting function, and the dotting logics of the point data under different type information are no longer processed separately. This means that even if the number of point data increases significantly later, the maintenance cost of the point data will not increase significantly, thereby solving the problem of high maintenance cost of the point data, greatly improving the maintainability of the point data, and reducing the labor cost of dotting.
[0053] Embodiment 2
[0054] Figure 2It is a flowchart of a dotting method provided in the second embodiment of the present invention. This embodiment is optimized based on the above technical solutions. In this embodiment, optionally, target data whose point information includes type information is screened out from each point data, and dotting is performed based on the dotting logic matching the type information of the target data. Specifically, it may include: taking the starting position information as the current position information, and taking the point information of the point data corresponding to the current position information as the current information; if the current information includes type information, taking the point data corresponding to the current information as the target data, using the type information of the target data as the input parameter, and implementing the dotting function by calling the when function, where the when function is used to screen out the dotting logic from each candidate logic and implement the dotting function by executing the dotting logic; updating the next position information of the current information to the current information, and repeating the step of taking the point information of the point data corresponding to the current position information as the current information until the current information is the end position information. Among them, the explanations of the same or corresponding terms as those in the above embodiments will not be repeated here.
[0055] See Figure 2 , the method of this embodiment may specifically include the following steps:
[0056] S210. When a dotting trigger event is detected, obtain the dotting parameters corresponding to the trigger event, where the dotting parameters include starting position information, ending position information, and type information.
[0057] S220. Using the dotting parameters as input parameters, call the already constructed dotting function, so that the dotting function implements the dotting function by executing S230 - S260 according to the input parameters.
[0058] S230. Obtain the adapter object of the list page where the starting position information is located. If the adapter object is not empty and the starting position information meets the preset display conditions, obtain the point information of each point data set between the starting position information and the ending position information based on the adapter object.
[0059] S240. Take the starting position information as the current position information, and take the point information of the point data corresponding to the current position information as the current information.
[0060] S250. If the current information includes type information, take the point data corresponding to the current information as the target data, use the type information of the target data as the input parameter, and implement the dotting function by calling the when function, where the when function is used to screen out the dotting logic from each candidate logic and implement the dotting function by executing the dotting logic.
[0061] Among them, compared with the logical screening based on the commonly used if-else, the screening method of the when function can effectively solve the problems of code redundancy and low efficiency in if-else, thereby achieving the effect of fast dotting. Exemplarily, the optional form of the when function is as follows:
[0062]
[0063] Among them, itemWrapper.type can be the type information in the point position information of the target data. As the input parameter of the when function, different type information corresponds to different dotting logics. Dotting logic 1, dotting logic 2, and dotting logic 3 are all candidate logics. According to the input parameter, the dotting logic that matches the target data can be selected from each candidate logic, and the dotting function can be implemented based on this dotting logic.
[0064] S260. Update the next position information of the current information to the current information, and repeat the step of taking the point position information corresponding to the current position information as the current information until the current information is the end position information.
[0065] Among them, in practical applications, there may be multiple point position data between the start position corresponding to the start position information and the end position corresponding to the end position information. At this time, the multiple point position data can be processed sequentially based on a loop method. Optionally, the enhanced for loop can be used to traverse and process each point position data. The performance of the enhanced for loop is much higher than that of the traditional for loop. Exemplarily, the specific form of the enhanced for loop can be for(index instartIndex until endIndex+1){}, where startIndex is the start position information and endIndex is the end position information. In this loop body, the point position information of the point position data with the position information of index can be obtained by calling the method val itemWrapper=adapter.getItem(index), and this point position information is marked as itemWrapper. As described in the main text, subsequently, the when(itemWrapper.type){} function can be called to screen each candidate logic according to the type information (itemWrapper.type) in the point position information, and the dotting function can be implemented based on the screening result.
[0066] In the technical solution of the embodiment of the present invention, by using the starting position information as the current position information, and using the point information of the point data corresponding to the current position information as the current information, the point data corresponding to the current information including the type information can be used as the target data. Using the type information of the target data as the input parameter, the dotting logic is filtered out from each candidate logic by calling the when function, and the dotting function is implemented by executing the dotting logic. By processing each point data in the above-mentioned manner, the effect of sequentially and quickly executing the dotting logics of each point data that meets the type information is achieved.
[0067] Embodiment III
[0068] Figure 3 It is a flowchart of a dotting method provided in Embodiment III of the present invention. This embodiment is optimized based on the above-mentioned technical solutions. In this embodiment, optionally, the dotting function is a rewritten function in the abstract subclass. The abstract subclass inherits from the abstract base class. The rewritten function is an abstract function in the abstract base class. The abstract base class is the base class set in the position calculation logic, and the abstract function is the function injected into the position calculation logic. The explanations of the same or corresponding terms as those in the above embodiments will not be elaborated here.
[0069] See Figure 3 , the method of this embodiment may specifically include the following steps:
[0070] S310. When a dotting trigger event is detected, obtain the dotting parameters corresponding to the trigger event, where the dotting parameters include starting position information, ending position information, and type information.
[0071] S320. Using the dotting parameters as the input parameters, call the constructed dotting function, so that the dotting function executes S330 and S340 according to the input parameters to implement the dotting function, where the dotting function is a rewritten function in the abstract subclass, the abstract subclass inherits from the abstract base class, the rewritten function is an abstract function in the abstract base class, the abstract base class is the base class set in the position calculation logic, and the abstract function is the function injected into the position calculation logic.
[0072] Among them, in the prior art, the dotting logic and the position calculation logic are intertwined, and the two interacting business logics are likely to affect the dotting efficiency. To solve this problem, the embodiments of the present invention propose to completely separate the dotting logic from the complex position calculation logic, and use the dotting function as a rewritten function in an abstract subclass. The abstract subclass inherits from an abstract base class. The rewritten function is an abstract function in the abstract base class, and the abstract base class is a base class set in the position calculation logic. The abstract function is a function that has been injected into the position calculation logic. In this way, the abstract function is rewritten, and the dotting function is a pure dotting logic that does not involve the position calculation logic, and the position calculation logic no longer involves any dotting logic, thus realizing a complete separation of the two logics. On this basis, optionally, the abstract base class can inherit from DYBaseLazyFragmentFragment in the Android system, and such an abstract base class can have functions such as page display function and lazy loading function.
[0073] In practical applications, optionally, an abstract base class is pre-constructed that inherits from DYBaseLazyFragmentFragment in the Android system. The optional construction process of this abstract base class VMZBaseFragment is as follows: abstract class VMZBaseFragment: DYBaseLazyFragment() {}. An abstract function onScrollShowPoint that can implement the dotting function is constructed in VMZBaseFragment, and its specific form can be as shown in Embodiment 1. Since onScrollShowPoint is an abstract function, it does not have actual function points and cannot be directly called. Therefore, it can be injected into the position calculation logic. This injection result makes the VMZBaseFragment set in the position calculation logic, and an abstract subclass VodPointFragment that inherits from the VMZBaseFragment is constructed. For example, VodPointFragment is constructed through class VodPointFragment: VMZBaseFragment(), and onScrollShowPoint is overridden in VodPointFragment. This is because VMZBaseFragment is an abstract base class, so VodPointFragment that inherits from it needs to override the abstract function onScrollShowPoint in the VMZBaseFragment. For example, the override of the abstract function is achieved in the following way: override fun onScrollShowPoint(startIndex: Int, endIndex: Int, pageType: Int?){}. Thus, a dotting function with actual function points and can be directly called is obtained.
[0074] S330. Obtain the adapter object of the list page where the starting position information is located. If the adapter object is not null and the starting position information meets the preset display conditions, obtain the point information of each point data set between the starting position information and the ending position information based on the adapter object.
[0075] S340. Screen out the target data whose point information includes type information from each point data, and perform dotting based on the dotting logic matching the type information of the target data.
[0076] In the technical solution of the embodiment of the present invention, the dotting logic and the complex position calculation logic are completely separated. The dotting function is used as an overridden function rewritten in the abstract subclass. The abstract subclass inherits from the abstract base class. The overridden function is an abstract function in the abstract base class. The abstract base class is a base class set in the position calculation logic. The abstract function is a function injected into the position calculation logic. In this way, the abstract function is overridden, and the dotting function is pure dotting logic, which does not involve the position calculation logic, and the position calculation logic no longer involves any dotting logic, thus achieving the effect of completely separating the two logics, and further achieving the effect of improving the dotting efficiency.
[0077] An optional technical solution is that the abstract function is pre-injected into the position calculation logic through the following steps: Obtain the list view object of the list view set in the list page. The list view can be an object that has been constructed and instantiated. Exemplarily, a list view object recyclerView can be constructed first by calling private var recyclerView: RecyclerView? = null, and then the recyclerView object can be instantiated by calling the recyclerView = view.findViewById(R.id.recycler_view) function; Based on the list view object, obtain the scroll listener function for listening to the scroll logic of the list view. Exemplarily, the scroll listening logic of the list view can be implemented by calling the recyclerView?.addOnScrollListener(object: OptimizedScrollListener()) function; When it is detected that the list view has scrolled based on the scroll listener function, override the callback function in the scroll listener function, and inject the abstract function into the position calculation logic based on the overridden callback function. Exemplarily, override the following callback function in OptimizedScrollListener: override fun onScrolled(recyclerView: RecyclerView?, dx: Int, dy: Int). The onScrolled function represents the change information when the scroll logic of the list view occurs. The injection logic of the abstract function can be implemented in the method body of the onScrolled function.
[0078] On this basis, optionally, the callback function after replication injects the abstract function into the position calculation logic through the following steps: when the list view object is not null, calculate the start position information of each point data by calling the start position calculation function in the list view object, and calculate the end position information of each point data by calling the end position calculation function in the list view object. Exemplarily, call the if(gridLayoutManager == null){return} function to check if the manager object gridLayoutManager of the list view object is null. If it is null, directly return through return. Otherwise, call the val firstCompletelyVisibleItemPosition = gridLayoutManager!!.findFirstCompletelyVisibleItemPosition() function to obtain the start position information of each point data. Each of these point data is data that can be displayed, which can be called visible elements, and assign the start position information to the firstCompletelyVisibleItemPosition variable. You can also call the vallastCompletelyVisibleItemPosition = gridLayoutManager!!.findLastCompletelyVisibleItemPosition() function to obtain the end position information of the visible elements and assign the end position information to the lastCompletelyVisibleItemPosition variable; further, obtain the type information of the list view by calling the type information acquisition function. Exemplarily, this type information acquisition function can be the pageType() function; thus, the start position information, end position information, and type information can be used as input parameters to inject the abstract function by calling the abstract function. Exemplarily, call the onScrollShowPoint(firstCompletelyVisibleItemPosition,lastCompletelyVisibleItemPosition,pageType()) function to achieve the injection of the abstract function.
[0079] To better understand the specific implementation process of the above steps, the following uses a specific example to exemplarily illustrate the dotting method applied to the Android system in this embodiment. Exemplarily, first, an abstract base class VMZBaseFragment is constructed through abstract class VMZBaseFragment: DYBaseLazyFragment() {}. This VMZBaseFragment inherits from DYBaseLazyFragment in the Android system and has the page display function and lazy loading function. An abstract function for implementing the dotting function is constructed in this VMZBaseFragment. For example, abstract fun onScrollShowPoint(startIndex: Int, endIndex: Int, pageType: Int?), where onScrollShowPoint is the name of the abstract function, and it has three parameters: the starting position information startIndex of type Int, the ending position information endIndex of type Int, and the type information pageType of type Int.
[0080] Since the abstract function onScrollShowPoint does not have actual functional points and cannot be directly called, the onScrollShowPoint can be injected into the position calculation logic. The injection process is as follows: A list view object RecyclerView is constructed by calling private var recyclerView: RecyclerView? = null, and then the recyclerView object is instantiated by calling the recyclerView = view.findViewById(R.id.recycler_view) function. Next, the listening logic for the list view scrolling is implemented by calling the recyclerView?.addOnScrollListener(object: OptimizedScrollListener()) function, and then the following callback function in OptimizedScrollListener is overridden: override fun onScrolled(recyclerView: RecyclerView?, dx: Int, dy: Int). Here, the onScrolled function represents the change information when the list view has a scrolling logic. Then, the injection logic of the abstract function shown below is implemented in the method body of the onScrolled function.
[0081] First, the manager object `gridLayoutManager` of the list view object is checked for null by calling the function `if (gridLayoutManager == null) { return;}`. If it is null, it can be directly returned through `return`. Otherwise, the starting position information of each point data can be obtained by calling the function `val firstCompletelyVisibleItemPosition = gridLayoutManager!!.findFirstCompletelyVisibleItemPosition()`. Each piece of this point data is data that can be displayed, which can be called visible elements, and this starting position information is assigned to the variable `firstCompletelyVisibleItemPosition`. The ending position information of the visible elements can also be obtained by calling the function `val lastCompletelyVisibleItemPosition = gridLayoutManager!!.findLastCompletelyVisibleItemPosition()`, and this ending position information is assigned to the variable `lastCompletelyVisibleItemPosition`. Next, the injection of the abstract function is implemented by calling the function `onScrollShowPoint(firstCompletelyVisibleItemPosition, lastCompletelyVisibleItemPosition, pageType())`. Among them, the function `pageType()` can return the type information of the list view.
[0082] After injecting the abstract function into the position calculation logic, an abstract subclass can be constructed in the position calculation logic, and then the abstract function can be overridden in the abstract subclass. The overriding process of the abstract function depends on the injection process of the abstract function, and then the dotting function is implemented in the overriding logic. Specifically, an abstract subclass VodPointFragment that inherits from VMZBaseFragment is constructed through class VodPointFragment: VMZBaseFragment(). Since VMZBaseFragment is an abstract base class, onScrollShowPoint in the abstract base class needs to be overridden in VodPointFragment. The specific overriding logic is as follows: override fun onScrollShowPoint(startIndex:Int,endIndex:Int,pageType:Int?){}. In the logic body of this overriding function, the adapter object adapter of the list elements is obtained by calling the val adapter = adapterInstance() function.
[0083] Next, some fault tolerance processing is performed to avoid exceptions in the Android system caused by the dotting function. Specifically, by calling if(adapter?.getAllData() == null || adapter.getAllData().isEmpty()){return}, when adapter?.getAllData() is null, it means the data in the adapter object is empty, or when adapter.getAllData().isEmpty() means there is no data in the adapter object, the dotting function of the list view can be ended by calling return. Next, the starting position information is further verified. Specifically, if(startIndex < 0){return}, when the starting position information is less than 0, it means the position information calculation of the point data is incorrect, and at this time, the dotting process can also be terminated by return.
[0084] Next, use an enhanced for loop to traverse and process the data at each point. Specifically, it is for (index in startIndex until endIndex + 1) {}, in this loop body, you can obtain the point information of the point data at position index by calling the method val itemWrapper = adapter.getItem(index), and mark this point information as itemWrapper. Then, you can screen each candidate logic according to the type information (itemWrapper.type) in the point information by calling the when (itemWrapper.type) {} function. The specific implementation of when is as follows:
[0085]
[0086] In this way, the dotting logics of the point data under different type information can be gathered together, and the complex position calculation logic is completely separated from the dotting function, greatly improving the maintainability of the point data and reducing the labor cost of dotting.
[0087] Embodiment 4
[0088] Figure 4 FIG. 13 is a structural block diagram of a dotting device provided in Embodiment 4 of the present invention. The device is used to execute the dotting method provided in any of the above embodiments. The device and the dotting methods of the above embodiments belong to the same inventive concept. For the details not described in detail in the embodiment of the dotting device, reference can be made to the embodiments of the above dotting methods. Refer to Figure 4 , the device may specifically include: a parameter acquisition module 410 and a dotting module 420. Among them, the dotting module 420 can implement the dotting function through the following sub-modules:
[0089] A point information acquisition sub-module 4201, configured to obtain an adapter object of the list page where the starting position information is located. If the adapter object is not empty and the starting position information meets the preset display condition, obtain the point information of each point data set between the starting position information and the ending position information based on the adapter object;
[0090] A dotting sub-module 4202, configured to screen out target data whose point information includes type information from each point data, and perform dotting based on a dotting logic matching the type information of the target data.
[0091] Optionally, the dotting sub-module 4202 may specifically include:
[0092] A current information determination unit, configured to use the starting position information as the current position information, and use the point information of the point data corresponding to the current position information as the current information;
[0093] A dotting unit, which is used to, if the current information includes type information, use the point data corresponding to the current information as the target data, use the type information of the target data as the input parameter, and implement the dotting function by calling the when function. The when function is used to screen out the dotting logic from each candidate logic according to the input parameter and implement the dotting function by executing the dotting logic;
[0094] A repeated execution unit, which is used to update the next position information of the current information to the current information and repeatedly execute the step of using the point information of the point data corresponding to the current position information as the current information until the current information is the end position information.
[0095] Optionally, on the basis of the above device, the device may further include:
[0096] An exit module, which is used to perform a return operation to exit the dotting function if the adapter object is empty and / or the start position information does not meet the preset display conditions.
[0097] Optionally, the dotting function is a rewritten function in an abstract subclass. The abstract subclass inherits from an abstract base class. The rewritten function is an abstract function in the abstract base class. The abstract base class is a base class set in the position calculation logic, and the abstract function is a function injected into the position calculation logic.
[0098] On this basis, optionally, the abstract function is pre-injected into the position calculation logic through the following module:
[0099] A scroll listening function acquisition module, which is used to acquire the list view object of the list view set on the list page and acquire the scroll listening function for listening to the scroll logic of the list view based on the list view object; an abstract function injection module, which is used to rewrite the callback function in the scroll listening function when it is detected based on the scroll listening function that the list view has scrolled, and inject the abstract function into the position calculation logic based on the rewritten callback function.
[0100] On this basis, optionally, the rewritten callback function injects the abstract function into the position calculation logic through the following sub-modules: a position information acquisition sub-module, which is used to calculate the start position information of each point data by calling the start position calculation function in the list view object and calculate the end position information of each point data by calling the end position calculation function in the list view object when the list view object is not empty; a type information acquisition sub-module, which is used to acquire the type information of the list view by calling the type information acquisition function; an abstract function injection sub-module, which is used to use the start position information, the end position information, and the type information as input parameters and implement the injection of the abstract function by calling the abstract function.
[0101] Optionally, the abstract base class inherits from DYBaseLazyFragmentFragment in the Android system, so that the abstract base class has the page display function and / or the lazy loading function; and / or,
[0102] The type information includes at least one of a list view, a button, a home page, and a control.
[0103] The dotting device provided in the fourth embodiment of the present invention, through the cooperation of the parameter acquisition module and the dotting module, when detecting a dotting trigger event, uses the dotting parameter corresponding to the trigger event as the input parameter, and the input parameter may include start position information, end position information, and type information, and calls the constructed dotting function, so that the dotting function cooperates with the point position information acquisition sub-module and the dotting sub-module, obtains the adapter object of the list page where the start position information is located according to the input parameter, if the adapter object is not empty and the start position information meets the preset display condition, then the point position information of each point data set between the start position information and the end position information can be obtained based on the adapter object, and the target data whose point position information meets the type information is filtered out from each point data, and then the target data is dotted based on the dotting logic matching the type information of the target data. The above device gathers the dotting logics of the point data under different type information based on the dotting function, and the dotting logics of the point data under different type information are no longer processed dispersedly, which means that even if the number of point data increases significantly later, the maintenance cost of the point data will not increase significantly, thus solving the problem of high maintenance cost of the point data, greatly improving the maintainability of the point data, and reducing the labor cost of dotting.
[0104] The dotting device provided in the embodiments of the present invention can execute the dotting method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the executed method.
[0105] It should be noted that in the embodiments of the above dotting device, the included units and modules are only divided according to the functional logic, but are not limited to the above division, as long as the corresponding functions can be realized; in addition, the specific names of the functional units are only for the convenience of mutual distinction and do not limit the protection scope of the present invention.
[0106] Embodiment 5
[0107] Figure 5 As shown in the structural schematic diagram of an electronic device provided in Embodiment 5 of the present invention, Figure 5 as shown, the electronic device includes a memory 510, a processor 520, an input device 530, and an output device 540. The number of processors 520 in the electronic device can be one or more, Figure 5Taking a processor 520 as an example; the memory 510, the processor 520, the input device 530, and the output device 540 in the electronic device can be connected through a bus or other means, Figure 5 Taking the connection through the bus 550 as an example.
[0108] The memory 510, as a computer-readable storage medium, can be used to store software programs, computer-executable programs, and modules, such as the program instructions / modules corresponding to the dotting method in the embodiments of the present invention (for example, the parameter acquisition module 410 and the dotting module 420 in the dotting device). The processor 520 executes various functional applications and data processing of the electronic device by running the software programs, instructions, and modules stored in the memory 510, that is, implements the above-mentioned dotting method.
[0109] The memory 510 may mainly include a program storage area and a data storage area. Among them, the program storage area can store an operating system and application programs required for at least one function; the data storage area can store data created according to the use of the electronic device, etc. In addition, the memory 510 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one magnetic disk storage device, a flash memory device, or other non-volatile solid-state storage devices. In some instances, the memory 510 may further include a memory remotely set relative to the processor 520, and these remote memories can be connected to the device through a network. Examples of the above network include but are not limited to the Internet, enterprise intranets, local area networks, mobile communication networks, and their combinations.
[0110] The input device 530 can be used to receive input digital or character information, and generate key signal inputs related to the user settings and function controls of the device. The output device 540 may include display devices such as a display screen.
[0111] Embodiment Six
[0112] Embodiment Six of the present invention provides a storage medium containing computer-executable instructions, and the computer-executable instructions are used to execute a dotting method when executed by a computer processor. The method includes:
[0113] When a trigger event for dotting is detected, obtain dotting parameters corresponding to the trigger event, where the dotting parameters include start position information, end position information, and type information;
[0114] Taking the dotting parameters as input parameters, call the already constructed dotting function, so that the dotting function implements the dotting function according to the input parameters;
[0115] Among them, the dotting function implements the dotting function through the following steps:
[0116] Obtain the adapter object of the list page where the starting position information is located. If the adapter object is not null and the starting position information meets the preset display conditions, obtain the point information of each point data set between the starting position information and the ending position information based on the adapter object;
[0117] Screen out the target data whose point information includes type information from each point data, and perform dotting based on the dotting logic matching the type information of the target data.
[0118] Of course, for a storage medium containing computer-executable instructions provided by an embodiment of the present invention, the computer-executable instructions are not limited to the method operations described above, and can also execute related operations in the dotting methods provided by any embodiment of the present invention.
[0119] From the above description of the embodiments, those skilled in the art can clearly understand that the present invention can be implemented by means of software and necessary general hardware. Of course, it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. The computer software product can be stored in a computer-readable storage medium, such as a floppy disk, read-only memory (ROM), random access memory (RAM), flash memory (FLASH), hard disk, or optical disc of a computer, etc., including several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in various embodiments of the present invention.
[0120] Note that the above is only a preferred embodiment of the present invention and the technical principles applied. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described here, and various obvious changes, re-adjustments, and substitutions can be made by those skilled in the art without departing from the protection scope of the present invention. Therefore, although the present invention has been described in detail through the above embodiments, the present invention is not limited to the above embodiments. Without departing from the concept of the present invention, it can also include more other equivalent embodiments, and the scope of the present invention is determined by the scope of the appended claims.
Claims
1. A dotting method, characterized in that, Including: When a triggering event for dotting is detected, obtain dotting parameters corresponding to the triggering event, where the dotting parameters include start position information, end position information, and type information; Use the dotting parameters as input parameters to call a constructed dotting function, so that the dotting function implements the dotting function according to the input parameters; Among them, the dotting function implements the dotting function through the following steps: Obtain an adapter object of the list page where the start position information is located. If the adapter object is not empty and the start position information meets the preset display conditions, obtain the position information of each point data set between the start position information and the end position information based on the adapter object; Filter out target data whose position information includes the type information from each point data, and perform dotting based on the dotting logic matching the type information of the target data; The filtering out of target data whose position information includes the type information from each point data and performing dotting based on the dotting logic matching the type information of the target data includes: Use the start position information as the current position information, and use the position information of the point data corresponding to the current position information as the current information; If the current information includes the type information, use the point data corresponding to the current information as the target data, and use the type information of the target data as the input parameter to implement the dotting function by calling the when function, where the when function is used to filter out the dotting logic from each candidate logic and implement the dotting function by executing the dotting logic; Update the next position information of the current information to the current information, and repeat the step of using the position information of the point data corresponding to the current position information as the current information until the current information is the end position information; The dotting function is a rewritten function in an abstract subclass. The abstract subclass inherits from an abstract base class. The rewritten function is an abstract function in the abstract base class. The abstract base class is a base class set in the position calculation logic, and the abstract function is a function injected into the position calculation logic; The abstract base class inherits from DYBaseLazyFragmentFragment in the Android system, so that the abstract base class has page display function and / or lazy loading function; The type information includes at least one of list view, button, home page, and control.
2. The method according to claim 1, characterized in that, Also including: If the adapter object is empty and / or the start position information does not meet the preset display conditions, perform a return operation to exit the dotting function.
3. The method according to claim 1, wherein The abstract function is pre-injected into the position calculation logic through the following steps: Obtain a list view object of the list view set in the list page, and obtain a scroll listening function for listening to the scroll logic of the list view based on the list view object; When the scrolling of the list view is detected based on the scroll monitoring function, the callback function in the scroll monitoring function is overwritten, and the abstract function is injected into the position calculation logic based on the overwritten callback function.
4. The method according to claim 3, characterized in that, The copied callback function injects the abstract function into the position calculation logic through the following steps: When the list view object is not empty, the starting position information of each point data is calculated by calling a starting position calculation function in the list view object, and the ending position information of each point data is calculated by calling an ending position calculation function in the list view object; Acquire the type information of the list view by calling a type information acquisition function; The starting position information, the ending position information and the type information are used as input parameters, and the injection of the abstract function is achieved by calling the abstract function.
5. A dotting device, characterized in that, include: A parameter acquisition module, used for acquiring the dotting parameters corresponding to the triggering event when a dotting triggering event is detected, wherein the dotting parameters include starting position information, ending position information and type information; A dotting module, used to call the constructed dotting function with the dotting parameters as input parameters, so that the dotting function realizes the dotting function according to the input parameters; The dotting function is implemented through the following submodules: A point information acquisition submodule, used to acquire the adapter object of the list page where the starting position information is located, and if the adapter object is not empty and the starting position information meets the preset display condition, then based on the adapter object, respectively acquire the point information of each point data set between the starting position information and the ending position information; A dotting submodule, used for filtering out the target data whose point information includes the type information from each of the point data, and performing dotting based on a dotting logic matching the type information of the target data; The dot-finding submodule specifically includes: a current information determining unit, configured to use the starting position information as current position information, and use the point information of the point data corresponding to the current position information as current information; A dotting unit, for, if the current information includes the type information, using the point data corresponding to the current information as target data, using the type information of the target data as an input parameter, and implementing a dotting function by calling a when function, wherein the when function is used to filter out dotting logic from each candidate logic according to the input parameter, and implementing the dotting function by executing the dotting logic; a repeating execution unit, configured to update the next position information of the current information to the current information, and repeatedly execute the step of using the point information of the point data corresponding to the current position information as the current information, until the current information is the end position information; The dotting function is a overridden function rewritten in an abstract subclass, the abstract subclass inherits from an abstract base class, the overridden function is an abstract function in the abstract base class, the abstract base class is a base class set in the position calculation logic, and the abstract function is a function injected into the position calculation logic; The abstract base class inherits from DYBaseLazyFragmentFragment in the Android system so that the abstract base class has a page display function and / or a lazy loading function; The type information includes at least one of a list view, a button, a home page, and a control.
6. An electronic device, characterized in that, Comprising: One or more processors; A memory for storing one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the dotting method as described in any one of claims 1-4.
7. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the dotting method as described in any one of claims 1-4.
Citation Information
Patent Citations
Dotting method and device, terminal and storage medium
CN110717130A
Method, device and system for collecting dotting information at client application
CN111193613A