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
3e259021
Commit
3e259021
authored
Nov 12, 2016
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sort module/repo by name
parent
f69facc8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
82 additions
and
28 deletions
+82
-28
BaseModule.java
...src/main/java/com/topjohnwu/magisk/module/BaseModule.java
+8
-1
Repo.java
app/src/main/java/com/topjohnwu/magisk/module/Repo.java
+6
-7
ModuleHelper.java
...rc/main/java/com/topjohnwu/magisk/utils/ModuleHelper.java
+68
-20
No files found.
app/src/main/java/com/topjohnwu/magisk/module/BaseModule.java
View file @
3e259021
package
com
.
topjohnwu
.
magisk
.
module
;
package
com
.
topjohnwu
.
magisk
.
module
;
import
android.support.annotation.NonNull
;
import
com.topjohnwu.magisk.utils.Logger
;
import
com.topjohnwu.magisk.utils.Logger
;
import
java.util.List
;
import
java.util.List
;
public
abstract
class
BaseModule
{
public
abstract
class
BaseModule
implements
Comparable
<
BaseModule
>
{
protected
String
mId
,
mName
,
mVersion
,
mAuthor
,
mDescription
,
mSupportUrl
,
mDonateUrl
;
protected
String
mId
,
mName
,
mVersion
,
mAuthor
,
mDescription
,
mSupportUrl
,
mDonateUrl
;
protected
boolean
mIsCacheModule
=
false
;
protected
boolean
mIsCacheModule
=
false
;
...
@@ -98,4 +100,9 @@ public abstract class BaseModule {
...
@@ -98,4 +100,9 @@ public abstract class BaseModule {
Logger
.
dev
(
"Cache mods are no longer supported! id: "
+
id
);
Logger
.
dev
(
"Cache mods are no longer supported! id: "
+
id
);
}
}
}
}
@Override
public
int
compareTo
(
@NonNull
BaseModule
o
)
{
return
this
.
getName
().
toLowerCase
().
compareTo
(
o
.
getName
().
toLowerCase
());
}
}
}
app/src/main/java/com/topjohnwu/magisk/module/Repo.java
View file @
3e259021
...
@@ -9,20 +9,19 @@ import com.topjohnwu.magisk.utils.WebRequest;
...
@@ -9,20 +9,19 @@ import com.topjohnwu.magisk.utils.WebRequest;
import
java.util.Date
;
import
java.util.Date
;
public
class
Repo
extends
BaseModule
{
public
class
Repo
extends
BaseModule
{
pr
otected
String
repoName
,
mLogUrl
,
mManifestUrl
,
mZipUrl
;
pr
ivate
String
mLogUrl
,
mManifestUrl
,
mZipUrl
;
pr
otected
Date
mLastUpdate
;
pr
ivate
Date
mLastUpdate
;
public
Repo
(
Context
context
,
String
name
,
Date
lastUpdate
)
throws
CacheModException
{
public
Repo
(
Context
context
,
String
name
,
Date
lastUpdate
)
throws
CacheModException
{
repoName
=
name
;
mLastUpdate
=
lastUpdate
;
mLastUpdate
=
lastUpdate
;
mLogUrl
=
context
.
getString
(
R
.
string
.
file_url
,
repoN
ame
,
"changelog.txt"
);
mLogUrl
=
context
.
getString
(
R
.
string
.
file_url
,
n
ame
,
"changelog.txt"
);
mManifestUrl
=
context
.
getString
(
R
.
string
.
file_url
,
repoN
ame
,
"module.prop"
);
mManifestUrl
=
context
.
getString
(
R
.
string
.
file_url
,
n
ame
,
"module.prop"
);
mZipUrl
=
context
.
getString
(
R
.
string
.
zip_url
,
repoN
ame
);
mZipUrl
=
context
.
getString
(
R
.
string
.
zip_url
,
n
ame
);
update
();
update
();
}
}
public
void
update
()
throws
CacheModException
{
public
void
update
()
throws
CacheModException
{
Logger
.
dev
(
"Repo: Re-fetch prop
"
+
mId
);
Logger
.
dev
(
"Repo: Re-fetch prop
"
);
String
props
=
WebRequest
.
makeWebServiceCall
(
mManifestUrl
,
WebRequest
.
GET
,
true
);
String
props
=
WebRequest
.
makeWebServiceCall
(
mManifestUrl
,
WebRequest
.
GET
,
true
);
String
lines
[]
=
props
.
split
(
"\\n"
);
String
lines
[]
=
props
.
split
(
"\\n"
);
parseProps
(
lines
);
parseProps
(
lines
);
...
...
app/src/main/java/com/topjohnwu/magisk/utils/ModuleHelper.java
View file @
3e259021
...
@@ -2,6 +2,7 @@ package com.topjohnwu.magisk.utils;
...
@@ -2,6 +2,7 @@ package com.topjohnwu.magisk.utils;
import
android.content.Context
;
import
android.content.Context
;
import
android.content.SharedPreferences
;
import
android.content.SharedPreferences
;
import
android.support.annotation.NonNull
;
import
com.google.gson.Gson
;
import
com.google.gson.Gson
;
import
com.google.gson.reflect.TypeToken
;
import
com.google.gson.reflect.TypeToken
;
...
@@ -16,19 +17,24 @@ import org.json.JSONObject;
...
@@ -16,19 +17,24 @@ import org.json.JSONObject;
import
java.text.ParseException
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.Comparator
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Locale
;
import
java.util.Locale
;
import
java.util.
Tree
Map
;
import
java.util.Map
;
public
class
ModuleHelper
{
public
class
ModuleHelper
{
public
static
final
String
MAGISK_PATH
=
"/magisk"
;
private
static
final
String
MAGISK_PATH
=
"/magisk"
;
private
static
final
String
FILE_KEY
=
"RepoMap"
;
private
static
final
String
REPO_KEY
=
"repomap"
;
private
static
final
String
VERSION_KEY
=
"version"
;
private
static
final
int
DATABASE_VER
=
1
;
private
static
final
String
file_key
=
"RepoMap"
;
private
static
ValueSortedMap
<
String
,
Repo
>
repoMap
=
new
ValueSortedMap
<>();
private
static
final
String
key
=
"repomap"
;
private
static
ValueSortedMap
<
String
,
Module
>
moduleMap
=
new
ValueSortedMap
<>();
private
static
TreeMap
<
String
,
Repo
>
repoMap
=
new
TreeMap
<>(
new
ModuleComparator
());
private
static
TreeMap
<
String
,
Module
>
moduleMap
=
new
TreeMap
<>(
new
ModuleComparator
());
public
static
void
createModuleMap
()
{
public
static
void
createModuleMap
()
{
...
@@ -54,24 +60,34 @@ public class ModuleHelper {
...
@@ -54,24 +60,34 @@ public class ModuleHelper {
repoMap
.
clear
();
repoMap
.
clear
();
Gson
gson
=
new
Gson
();
Gson
gson
=
new
Gson
();
SharedPreferences
prefs
=
context
.
getSharedPreferences
(
file_key
,
Context
.
MODE_PRIVATE
);
SharedPreferences
prefs
=
context
.
getSharedPreferences
(
FILE_KEY
,
Context
.
MODE_PRIVATE
);
String
jsonString
=
prefs
.
getString
(
key
,
null
);
String
jsonString
;
int
cachedVersion
=
prefs
.
getInt
(
VERSION_KEY
,
0
);
if
(
cachedVersion
!=
DATABASE_VER
)
{
// Ignore incompatible cached database
jsonString
=
null
;
}
else
{
jsonString
=
prefs
.
getString
(
REPO_KEY
,
null
);
}
Tree
Map
<
String
,
Repo
>
cached
=
null
;
ValueSorted
Map
<
String
,
Repo
>
cached
=
null
;
if
(
jsonString
!=
null
)
{
if
(
jsonString
!=
null
)
{
cached
=
gson
.
fromJson
(
jsonString
,
new
TypeToken
<
Tree
Map
<
String
,
Repo
>
>(){}.
getType
());
cached
=
gson
.
fromJson
(
jsonString
,
new
TypeToken
<
ValueSorted
Map
<
String
,
Repo
>
>(){}.
getType
());
}
}
if
(
cached
==
null
)
{
if
(
cached
==
null
)
{
cached
=
new
TreeMap
<>(
new
ModuleComparator
()
);
cached
=
new
ValueSortedMap
<>(
);
}
}
// Making a request to url and getting response
// Making a request to url and getting response
String
jsonStr
=
WebRequest
.
makeWebServiceCall
(
context
.
getString
(
R
.
string
.
url_main
)
+
Utils
.
getToken
(),
WebRequest
.
GET
);
jsonString
=
WebRequest
.
makeWebServiceCall
(
context
.
getString
(
R
.
string
.
url_main
)
+
Utils
.
getToken
(),
WebRequest
.
GET
);
if
(
jsonStr
!=
null
&&
!
jsonStr
.
isEmpty
())
{
if
(
jsonString
!=
null
&&
!
jsonString
.
isEmpty
())
{
// Have internet access
try
{
try
{
JSONArray
jsonArray
=
new
JSONArray
(
jsonStr
);
JSONArray
jsonArray
=
new
JSONArray
(
jsonStr
ing
);
for
(
int
i
=
0
;
i
<
jsonArray
.
length
();
i
++)
{
for
(
int
i
=
0
;
i
<
jsonArray
.
length
();
i
++)
{
JSONObject
jsonobject
=
jsonArray
.
getJSONObject
(
i
);
JSONObject
jsonobject
=
jsonArray
.
getJSONObject
(
i
);
String
id
=
jsonobject
.
getString
(
"description"
);
String
id
=
jsonobject
.
getString
(
"description"
);
...
@@ -101,10 +117,16 @@ public class ModuleHelper {
...
@@ -101,10 +117,16 @@ public class ModuleHelper {
}
catch
(
JSONException
e
)
{
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
}
else
{
prefs
.
edit
().
putString
(
key
,
gson
.
toJson
(
repoMap
)).
apply
();
// Use cached if no internet
repoMap
.
putAll
(
cached
);
}
}
prefs
.
edit
()
.
putInt
(
VERSION_KEY
,
DATABASE_VER
)
.
putString
(
REPO_KEY
,
gson
.
toJson
(
repoMap
))
.
apply
();
Logger
.
dev
(
"ModuleHelper: Repo load done"
);
Logger
.
dev
(
"ModuleHelper: Repo load done"
);
}
}
...
@@ -131,10 +153,36 @@ public class ModuleHelper {
...
@@ -131,10 +153,36 @@ public class ModuleHelper {
}
}
}
}
public
static
class
ModuleComparator
implements
Comparator
<
String
>
{
private
static
class
ValueSortedMap
<
K
,
V
extends
Comparable
>
extends
HashMap
<
K
,
V
>
{
private
List
<
V
>
sorted
=
new
ArrayList
<>();
@NonNull
@Override
public
Collection
<
V
>
values
()
{
if
(
sorted
.
isEmpty
())
{
sorted
.
addAll
(
super
.
values
());
Collections
.
sort
(
sorted
);
}
return
sorted
;
}
@Override
public
V
put
(
K
key
,
V
value
)
{
sorted
.
clear
();
return
super
.
put
(
key
,
value
);
}
@Override
public
void
putAll
(
Map
<?
extends
K
,
?
extends
V
>
m
)
{
sorted
.
clear
();
super
.
putAll
(
m
);
}
@Override
@Override
public
int
compare
(
String
o1
,
String
o2
)
{
public
V
remove
(
Object
key
)
{
return
o1
.
toLowerCase
().
compareTo
(
o2
.
toLowerCase
());
sorted
.
clear
();
return
super
.
remove
(
key
);
}
}
}
}
}
}
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