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
bef43617
Commit
bef43617
authored
Sep 02, 2016
by
d8ahazard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
That's important too...
parent
aa991b62
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
33 deletions
+50
-33
RepoAdapter.java
...rc/main/java/com/topjohnwu/magisk/module/RepoAdapter.java
+50
-33
No files found.
app/src/main/java/com/topjohnwu/magisk/module/RepoAdapter.java
View file @
bef43617
package
com
.
topjohnwu
.
magisk
.
module
;
import
android.app.ListActivity
;
import
android.content.Context
;
import
android.content.SharedPreferences
;
import
android.os.AsyncTask
;
import
android.os.Bundle
;
import
android.preference.PreferenceManager
;
import
android.util.Log
;
import
android.widget.Toast
;
import
com.topjohnwu.magisk.utils.WebRequest
;
...
...
@@ -14,9 +13,10 @@ import org.json.JSONArray;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
java.
net.MalformedURL
Exception
;
import
java.
net.URL
;
import
java.
text.Parse
Exception
;
import
java.
text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -27,42 +27,48 @@ public class RepoAdapter {
private
static
final
String
TAG_ID
=
"id"
;
private
static
final
String
TAG_NAME
=
"name"
;
private
Context
activityContext
;
private
Date
updatedDate
,
currentDate
;
public
List
<
Repo
>
listRepos
(
Context
context
)
{
public
List
<
Repo
>
listRepos
(
Context
context
,
boolean
refresh
)
{
SharedPreferences
prefs
=
PreferenceManager
.
getDefaultSharedPreferences
(
context
);
if
(!
prefs
.
contains
(
"hasCachedRepos"
))
{
if
(!
prefs
.
contains
(
"hasCachedRepos"
)
|
refresh
)
{
activityContext
=
context
;
MyAsyncTask
asynchTask
=
new
MyAsyncTask
();
asynchTask
.
execute
();
new
MyAsyncTask
().
execute
();
List
<
String
>
out
=
null
;
}
else
{
Log
.
d
(
"Magisk"
,
"Building from cache"
);
Map
<
String
,?>
map
=
prefs
.
getAll
();
for
(
Map
.
Entry
<
String
,?>
entry
:
map
.
entrySet
())
{
Map
<
String
,
?>
map
=
prefs
.
getAll
();
repos
.
clear
();
for
(
Map
.
Entry
<
String
,
?>
entry
:
map
.
entrySet
())
{
if
(
entry
.
getKey
().
contains
(
"module_"
))
{
String
repoString
=
entry
.
getValue
().
toString
();
String
repoString
=
entry
.
getValue
().
toString
()
.
replace
(
"""
,
"\""
)
;
JSONArray
repoArray
=
null
;
try
{
repoArray
=
new
JSONArray
(
repoString
);
repos
.
clear
();
for
(
int
f
=
0
;
f
<
repoArray
.
length
();
f
++)
{
JSONObject
jsonobject
=
repoArray
.
getJSONObject
(
f
);
String
name
=
jsonobject
.
getString
(
"name"
);
String
moduleName
,
moduleDescription
,
zipUrl
;
moduleName
=
jsonobject
.
getString
(
"moduleName"
);
moduleDescription
=
jsonobject
.
getString
(
"moduleDescription"
);
zipUrl
=
jsonobject
.
getString
(
"zipUrl"
);
repos
.
add
(
new
Repo
(
moduleName
,
moduleDescription
,
zipUrl
));
}
for
(
int
f
=
0
;
f
<
repoArray
.
length
();
f
++)
{
JSONObject
jsonobject
=
repoArray
.
getJSONObject
(
f
);
String
name
=
entry
.
getKey
().
replace
(
"module_"
,
""
);
name
=
name
.
replace
(
" "
,
""
);
String
moduleName
,
moduleDescription
,
zipUrl
;
moduleName
=
jsonobject
.
getString
(
"moduleName"
);
moduleDescription
=
jsonobject
.
getString
(
"moduleDescription"
);
zipUrl
=
jsonobject
.
getString
(
"zipUrl"
);
SimpleDateFormat
format
=
new
SimpleDateFormat
(
"yyyy-MM-dd'T'HH:mm:ss'Z'"
);
try
{
updatedDate
=
format
.
parse
(
jsonobject
.
getString
(
"lastUpdate"
));
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
}
repos
.
add
(
new
Repo
(
name
,
moduleDescription
,
zipUrl
,
updatedDate
,
activityContext
));
}
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
}
System
.
out
.
println
(
entry
.
getKey
()
+
"/"
+
entry
.
getValue
());
}
}
...
...
@@ -72,26 +78,31 @@ public class RepoAdapter {
}
class
MyAsyncTask
extends
AsyncTask
<
String
,
String
,
Void
>
{
@Override
protected
void
onPreExecute
()
{
super
.
onPreExecute
();
}
@Override
protected
void
onProgressUpdate
(
String
...
values
)
{
super
.
onProgressUpdate
(
values
);
Toast
.
makeText
(
activityContext
,
"Refreshing online modules"
,
Toast
.
LENGTH_SHORT
).
show
();
}
@Override
protected
Void
doInBackground
(
String
...
params
)
{
Log
.
d
(
"Magisk"
,
"doInBackground running"
);
publishProgress
(
);
// Creating service handler class instance
WebRequest
webreq
=
new
WebRequest
();
// Making a request to url and getting response
String
jsonStr
=
webreq
.
makeWebServiceCall
(
url
,
WebRequest
.
GET
);
Log
.
d
(
"Magisk"
,
"doInBackground Running, String: "
+
jsonStr
+
" Url: "
+
url
);
Log
.
d
(
"Response: "
,
"> "
+
jsonStr
);
try
{
repos
.
clear
();
...
...
@@ -100,11 +111,18 @@ public class RepoAdapter {
JSONObject
jsonobject
=
jsonArray
.
getJSONObject
(
i
);
String
name
=
jsonobject
.
getString
(
"name"
);
String
url
=
jsonobject
.
getString
(
"url"
);
if
(!
name
.
contains
(
"Repo.github.io"
))
{
repos
.
add
(
new
Repo
(
name
,
url
,
activityContext
));
}
for
(
int
f
=
0
;
f
<
repos
.
size
();
f
++)
{
repos
.
get
(
f
).
fetch
();
String
lastUpdate
=
jsonobject
.
getString
(
"updated_at"
);
SimpleDateFormat
format
=
new
SimpleDateFormat
(
"yyyy-MM-dd'T'HH:mm:ss'Z'"
);
try
{
updatedDate
=
format
.
parse
(
lastUpdate
);
}
catch
(
ParseException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
if
(!
name
.
contains
(
"Repo.github.io"
))
{
repos
.
add
(
new
Repo
(
name
,
url
,
updatedDate
,
activityContext
));
}
}
}
catch
(
JSONException
e
)
{
...
...
@@ -126,5 +144,4 @@ public class RepoAdapter {
}
}
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