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
162eeaa0
Commit
162eeaa0
authored
Mar 24, 2019
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve repo adapter
parent
f36ce905
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
35 deletions
+53
-35
ReposAdapter.java
...main/java/com/topjohnwu/magisk/adapters/ReposAdapter.java
+48
-30
ReposFragment.java
...in/java/com/topjohnwu/magisk/fragments/ReposFragment.java
+5
-5
No files found.
app/src/main/java/com/topjohnwu/magisk/adapters/ReposAdapter.java
View file @
162eeaa0
...
@@ -15,6 +15,7 @@ import android.widget.TextView;
...
@@ -15,6 +15,7 @@ import android.widget.TextView;
import
androidx.recyclerview.widget.RecyclerView
;
import
androidx.recyclerview.widget.RecyclerView
;
import
com.topjohnwu.magisk.App
;
import
com.topjohnwu.magisk.ClassMap
;
import
com.topjohnwu.magisk.ClassMap
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.components.BaseActivity
;
import
com.topjohnwu.magisk.components.BaseActivity
;
...
@@ -32,6 +33,7 @@ import java.util.List;
...
@@ -32,6 +33,7 @@ import java.util.List;
import
java.util.Map
;
import
java.util.Map
;
import
butterknife.BindView
;
import
butterknife.BindView
;
import
java9.util.stream.StreamSupport
;
public
class
ReposAdapter
public
class
ReposAdapter
extends
SectionedAdapter
<
ReposAdapter
.
SectionHolder
,
ReposAdapter
.
RepoHolder
>
extends
SectionedAdapter
<
ReposAdapter
.
SectionHolder
,
ReposAdapter
.
RepoHolder
>
...
@@ -41,18 +43,19 @@ public class ReposAdapter
...
@@ -41,18 +43,19 @@ public class ReposAdapter
private
static
final
int
INSTALLED
=
1
;
private
static
final
int
INSTALLED
=
1
;
private
static
final
int
OTHERS
=
2
;
private
static
final
int
OTHERS
=
2
;
private
Cursor
repoCursor
=
null
;
private
Map
<
String
,
Module
>
moduleMap
;
private
Map
<
String
,
Module
>
moduleMap
;
private
RepoDatabaseHelper
repoDB
;
private
RepoDatabaseHelper
repoDB
;
private
List
<
Pair
<
Integer
,
List
<
Repo
>>>
repoPairs
;
private
List
<
Pair
<
Integer
,
List
<
Repo
>>>
repoPairs
;
private
List
<
Repo
>
fullList
;
private
SearchView
mSearch
;
public
ReposAdapter
(
RepoDatabaseHelper
db
)
{
public
ReposAdapter
()
{
repoDB
=
db
;
repoDB
=
App
.
self
.
repoDB
;
moduleMap
=
Collections
.
emptyMap
();
moduleMap
=
Collections
.
emptyMap
();
fullList
=
Collections
.
emptyList
();
repoPairs
=
new
ArrayList
<>();
repoPairs
=
new
ArrayList
<>();
}
}
@Override
@Override
public
int
getSectionCount
()
{
public
int
getSectionCount
()
{
return
repoPairs
.
size
();
return
repoPairs
.
size
();
...
@@ -136,17 +139,36 @@ public class ReposAdapter
...
@@ -136,17 +139,36 @@ public class ReposAdapter
});
});
}
}
p
ublic
void
notifyDBChanged
()
{
p
rivate
void
updateLists
()
{
if
(
repoCursor
!=
null
)
if
(
mSearch
!=
null
)
repoCursor
.
close
(
);
onQueryTextChange
(
mSearch
.
getQuery
().
toString
()
);
repoCursor
=
repoDB
.
getRepoCursor
();
else
onQueryTextChange
(
""
);
onQueryTextChange
(
""
);
}
}
private
static
boolean
noCaseContain
(
String
a
,
String
b
)
{
return
a
.
toLowerCase
().
contains
(
b
.
toLowerCase
());
}
public
void
setSearchView
(
SearchView
view
)
{
mSearch
=
view
;
mSearch
.
setOnQueryTextListener
(
this
);
}
public
void
notifyDBChanged
(
boolean
refresh
)
{
try
(
Cursor
c
=
repoDB
.
getRepoCursor
())
{
fullList
=
new
ArrayList
<>(
c
.
getCount
());
while
(
c
.
moveToNext
())
fullList
.
add
(
new
Repo
(
c
));
}
if
(
refresh
)
updateLists
();
}
@Override
@Override
public
void
onEvent
(
int
event
)
{
public
void
onEvent
(
int
event
)
{
moduleMap
=
Event
.
getResult
(
event
);
moduleMap
=
Event
.
getResult
(
event
);
notifyDataSetChanged
();
updateLists
();
}
}
@Override
@Override
...
@@ -165,14 +187,11 @@ public class ReposAdapter
...
@@ -165,14 +187,11 @@ public class ReposAdapter
List
<
Repo
>
installed
=
new
ArrayList
<>();
List
<
Repo
>
installed
=
new
ArrayList
<>();
List
<
Repo
>
others
=
new
ArrayList
<>();
List
<
Repo
>
others
=
new
ArrayList
<>();
repoPairs
.
clear
();
StreamSupport
.
stream
(
fullList
)
while
(
repoCursor
.
moveToNext
())
{
.
filter
(
repo
->
noCaseContain
(
repo
.
getName
(),
s
)
Repo
repo
=
new
Repo
(
repoCursor
);
||
noCaseContain
(
repo
.
getAuthor
(),
s
)
if
(
repo
.
getName
().
toLowerCase
().
contains
(
s
.
toLowerCase
())
||
noCaseContain
(
repo
.
getDescription
(),
s
))
||
repo
.
getAuthor
().
toLowerCase
().
contains
(
s
.
toLowerCase
())
.
forEach
(
repo
->
{
||
repo
.
getDescription
().
toLowerCase
().
contains
(
s
.
toLowerCase
())
)
{
// Passed the repoFilter
Module
module
=
moduleMap
.
get
(
repo
.
getId
());
Module
module
=
moduleMap
.
get
(
repo
.
getId
());
if
(
module
!=
null
)
{
if
(
module
!=
null
)
{
if
(
repo
.
getVersionCode
()
>
module
.
getVersionCode
())
{
if
(
repo
.
getVersionCode
()
>
module
.
getVersionCode
())
{
...
@@ -184,10 +203,9 @@ public class ReposAdapter
...
@@ -184,10 +203,9 @@ public class ReposAdapter
}
else
{
}
else
{
others
.
add
(
repo
);
others
.
add
(
repo
);
}
}
}
});
}
repoCursor
.
moveToFirst
();
repoPairs
.
clear
();
if
(!
updates
.
isEmpty
())
if
(!
updates
.
isEmpty
())
repoPairs
.
add
(
new
Pair
<>(
UPDATES
,
updates
));
repoPairs
.
add
(
new
Pair
<>(
UPDATES
,
updates
));
if
(!
installed
.
isEmpty
())
if
(!
installed
.
isEmpty
())
...
...
app/src/main/java/com/topjohnwu/magisk/fragments/ReposFragment.java
View file @
162eeaa0
...
@@ -48,8 +48,7 @@ public class ReposFragment extends BaseFragment {
...
@@ -48,8 +48,7 @@ public class ReposFragment extends BaseFragment {
mSwipeRefreshLayout
.
setRefreshing
(
true
);
mSwipeRefreshLayout
.
setRefreshing
(
true
);
mSwipeRefreshLayout
.
setOnRefreshListener
(()
->
new
UpdateRepos
().
exec
(
true
));
mSwipeRefreshLayout
.
setOnRefreshListener
(()
->
new
UpdateRepos
().
exec
(
true
));
adapter
=
new
ReposAdapter
(
app
.
repoDB
);
adapter
=
new
ReposAdapter
();
Event
.
register
(
adapter
);
recyclerView
.
setAdapter
(
adapter
);
recyclerView
.
setAdapter
(
adapter
);
recyclerView
.
setVisibility
(
View
.
GONE
);
recyclerView
.
setVisibility
(
View
.
GONE
);
...
@@ -71,7 +70,8 @@ public class ReposFragment extends BaseFragment {
...
@@ -71,7 +70,8 @@ public class ReposFragment extends BaseFragment {
@Override
@Override
public
void
onEvent
(
int
event
)
{
public
void
onEvent
(
int
event
)
{
adapter
.
notifyDBChanged
();
adapter
.
notifyDBChanged
(
false
);
Event
.
register
(
adapter
);
mSwipeRefreshLayout
.
setRefreshing
(
false
);
mSwipeRefreshLayout
.
setRefreshing
(
false
);
boolean
empty
=
adapter
.
getItemCount
()
==
0
;
boolean
empty
=
adapter
.
getItemCount
()
==
0
;
recyclerView
.
setVisibility
(
empty
?
View
.
GONE
:
View
.
VISIBLE
);
recyclerView
.
setVisibility
(
empty
?
View
.
GONE
:
View
.
VISIBLE
);
...
@@ -82,7 +82,7 @@ public class ReposFragment extends BaseFragment {
...
@@ -82,7 +82,7 @@ public class ReposFragment extends BaseFragment {
public
void
onCreateOptionsMenu
(
Menu
menu
,
MenuInflater
inflater
)
{
public
void
onCreateOptionsMenu
(
Menu
menu
,
MenuInflater
inflater
)
{
inflater
.
inflate
(
R
.
menu
.
menu_repo
,
menu
);
inflater
.
inflate
(
R
.
menu
.
menu_repo
,
menu
);
SearchView
search
=
(
SearchView
)
menu
.
findItem
(
R
.
id
.
repo_search
).
getActionView
();
SearchView
search
=
(
SearchView
)
menu
.
findItem
(
R
.
id
.
repo_search
).
getActionView
();
search
.
setOnQueryTextListener
(
adapter
);
adapter
.
setSearchView
(
search
);
}
}
@Override
@Override
...
@@ -93,7 +93,7 @@ public class ReposFragment extends BaseFragment {
...
@@ -93,7 +93,7 @@ public class ReposFragment extends BaseFragment {
.
setSingleChoiceItems
(
R
.
array
.
sorting_orders
,
.
setSingleChoiceItems
(
R
.
array
.
sorting_orders
,
Config
.
get
(
Config
.
Key
.
REPO_ORDER
),
(
d
,
which
)
->
{
Config
.
get
(
Config
.
Key
.
REPO_ORDER
),
(
d
,
which
)
->
{
Config
.
set
(
Config
.
Key
.
REPO_ORDER
,
which
);
Config
.
set
(
Config
.
Key
.
REPO_ORDER
,
which
);
adapter
.
notifyDBChanged
();
adapter
.
notifyDBChanged
(
true
);
d
.
dismiss
();
d
.
dismiss
();
}).
show
();
}).
show
();
}
}
...
...
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