Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
Magisk
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Magisk
Commits
085fba05
Commit
085fba05
authored
Jul 23, 2017
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce self-written SectionedAdapter
parent
295334d3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
169 additions
and
113 deletions
+169
-113
ReposAdapter.java
...main/java/com/topjohnwu/magisk/adapters/ReposAdapter.java
+91
-113
SectionedAdapter.java
.../java/com/topjohnwu/magisk/adapters/SectionedAdapter.java
+78
-0
No files found.
app/src/main/java/com/topjohnwu/magisk/adapters/ReposAdapter.java
View file @
085fba05
This diff is collapsed.
Click to expand it.
app/src/main/java/com/topjohnwu/magisk/adapters/SectionedAdapter.java
0 → 100644
View file @
085fba05
package
com
.
topjohnwu
.
magisk
.
adapters
;
import
android.support.v7.widget.RecyclerView
;
import
android.view.ViewGroup
;
public
abstract
class
SectionedAdapter
<
S
extends
RecyclerView
.
ViewHolder
,
C
extends
RecyclerView
.
ViewHolder
>
extends
RecyclerView
.
Adapter
<
RecyclerView
.
ViewHolder
>
{
private
static
final
int
SECTION_TYPE
=
Integer
.
MIN_VALUE
;
@Override
final
public
RecyclerView
.
ViewHolder
onCreateViewHolder
(
ViewGroup
parent
,
int
viewType
)
{
if
(
viewType
==
SECTION_TYPE
)
return
onCreateSectionViewHolder
(
parent
);
return
onCreateItemViewHolder
(
parent
,
viewType
);
}
@Override
@SuppressWarnings
(
"unchecked"
)
final
public
void
onBindViewHolder
(
RecyclerView
.
ViewHolder
holder
,
int
position
)
{
PositionInfo
info
=
getPositionInfo
(
position
);
if
(
info
.
position
==
-
1
)
onBindSectionViewHolder
((
S
)
holder
,
info
.
section
);
else
onBindItemViewHolder
((
C
)
holder
,
info
.
section
,
info
.
position
);
}
@Override
final
public
int
getItemCount
()
{
int
size
,
sec
;
size
=
sec
=
getSectionCount
();
for
(
int
i
=
0
;
i
<
sec
;
++
i
){
size
+=
getItemCount
(
i
);
}
return
size
;
}
@Override
final
public
int
getItemViewType
(
int
position
)
{
PositionInfo
info
=
getPositionInfo
(
position
);
if
(
info
.
position
==
-
1
)
return
SECTION_TYPE
;
else
return
getItemViewType
(
info
.
section
,
info
.
position
);
}
public
int
getItemViewType
(
int
section
,
int
position
)
{
return
0
;
}
private
PositionInfo
getPositionInfo
(
int
position
)
{
int
section
=
0
;
while
(
true
)
{
if
(
position
==
0
)
return
new
PositionInfo
(
section
,
-
1
);
position
-=
1
;
if
(
position
<
getItemCount
(
section
))
return
new
PositionInfo
(
section
,
position
);
position
-=
getItemCount
(
section
++);
}
}
private
static
class
PositionInfo
{
int
section
;
int
position
;
PositionInfo
(
int
section
,
int
position
)
{
this
.
section
=
section
;
this
.
position
=
position
;
}
}
public
abstract
int
getSectionCount
();
public
abstract
int
getItemCount
(
int
section
);
public
abstract
S
onCreateSectionViewHolder
(
ViewGroup
parent
);
public
abstract
C
onCreateItemViewHolder
(
ViewGroup
parent
,
int
viewType
);
public
abstract
void
onBindSectionViewHolder
(
S
holder
,
int
section
);
public
abstract
void
onBindItemViewHolder
(
C
holder
,
int
section
,
int
position
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment