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
6a90340b
Commit
6a90340b
authored
Sep 14, 2016
by
d8ahazard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Work on file picker - WIP
parent
46abbfe2
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
69 additions
and
54 deletions
+69
-54
build.gradle
app/build.gradle
+2
-4
AndroidManifest.xml
app/src/main/AndroidManifest.xml
+4
-0
BaseModuleFragment.java
...rc/main/java/com/topjohnwu/magisk/BaseModuleFragment.java
+0
-3
ModulesFragment.java
app/src/main/java/com/topjohnwu/magisk/ModulesFragment.java
+59
-47
RepoHelper.java
...src/main/java/com/topjohnwu/magisk/module/RepoHelper.java
+4
-0
No files found.
app/build.gradle
View file @
6a90340b
...
...
@@ -26,9 +26,7 @@ android {
}
}
repositories
{
maven
{
url
"http://dl.bintray.com/lukaville/maven"
}
}
dependencies
{
...
...
@@ -36,7 +34,7 @@ dependencies {
compile
'com.android.support:recyclerview-v7:24.2.0'
compile
'com.android.support:cardview-v7:24.2.0'
compile
'com.android.support:design:24.2.0'
compile
'com.nbsp:library:1.1'
compile
'com.jakewharton:butterknife:8.4.0'
compile
'com.github.angads25:filepicker:1.0.6'
annotationProcessor
'com.jakewharton:butterknife-compiler:8.4.0'
}
app/src/main/AndroidManifest.xml
View file @
6a90340b
...
...
@@ -16,6 +16,7 @@
tools:ignore=
"AllowBackup,GoogleAppIndexingWarning"
>
<activity
android:name=
".WelcomeActivity"
android:exported=
"true"
android:configChanges=
"orientation|screenSize"
>
<intent-filter>
<action
android:name=
"android.intent.action.MAIN"
/>
...
...
@@ -23,9 +24,11 @@
<category
android:name=
"android.intent.category.LAUNCHER"
/>
</intent-filter>
</activity>
<activity
android:name=
".AboutActivity"
android:theme=
"@style/AppTheme.Transparent"
/>
<provider
android:name=
"android.support.v4.content.FileProvider"
android:authorities=
"com.topjohnwu.magisk.provider"
...
...
@@ -35,6 +38,7 @@
android:name=
"android.support.FILE_PROVIDER_PATHS"
android:resource=
"@xml/file_paths"
/>
</provider>
</application>
</manifest>
\ No newline at end of file
app/src/main/java/com/topjohnwu/magisk/BaseModuleFragment.java
View file @
6a90340b
...
...
@@ -167,9 +167,6 @@ public abstract class BaseModuleFragment extends Fragment {
String
logUrl
=
module
.
getmLogUrl
();
String
supportUrl
=
module
.
getmSupportUrl
();
String
donateUrl
=
module
.
getmDonateUrl
();
if
(
supportUrl
!=
null
&&
!
supportUrl
.
isEmpty
())
holder
.
supportLink
.
setBackgroundColor
(
Color
.
GRAY
);
if
(
logUrl
!=
null
&&
!
logUrl
.
isEmpty
())
holder
.
changeLog
.
setBackgroundColor
(
Color
.
GRAY
);
if
(
donateUrl
!=
null
&&
!
donateUrl
.
isEmpty
())
holder
.
authorLink
.
setBackgroundColor
(
Color
.
GRAY
);
SharedPreferences
prefs
=
PreferenceManager
.
getDefaultSharedPreferences
(
context
);
if
(
prefs
.
contains
(
"ignoreUpdateAlerts"
))
{
ignoreAlertUpdate
=
prefs
.
getBoolean
(
"ignoreUpdateAlerts"
,
false
);
...
...
app/src/main/java/com/topjohnwu/magisk/ModulesFragment.java
View file @
6a90340b
...
...
@@ -2,40 +2,46 @@ package com.topjohnwu.magisk;
import
android.app.Activity
;
import
android.content.Intent
;
import
android.content.SharedPreferences
;
import
android.net.Uri
;
import
android.os.AsyncTask
;
import
android.os.Bundle
;
import
android.preference.PreferenceManager
;
import
android.os.Environment
;
import
android.provider.DocumentsContract
;
import
android.support.annotation.Nullable
;
import
android.support.design.widget.FloatingActionButton
;
import
android.support.design.widget.TabLayout
;
import
android.support.v4.app.Fragment
;
import
android.support.v4.app.FragmentManager
;
import
android.support.v4.app.FragmentPagerAdapter
;
import
android.support.v4.provider.DocumentFile
;
import
android.support.v4.view.ViewPager
;
import
android.util.Log
;
import
android.view.LayoutInflater
;
import
android.view.Menu
;
import
android.view.MenuInflater
;
import
android.view.MenuItem
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.widget.ProgressBar
;
import
android.widget.Toast
;
import
com.nbsp.materialfilepicker.MaterialFilePicker
;
import
com.nbsp.materialfilepicker.ui.FilePickerActivity
;
import
com.github.angads25.filepicker.controller.DialogSelectionListener
;
import
com.github.angads25.filepicker.model.DialogConfigs
;
import
com.github.angads25.filepicker.model.DialogProperties
;
import
com.github.angads25.filepicker.view.FilePickerDialog
;
import
com.topjohnwu.magisk.module.Module
;
import
com.topjohnwu.magisk.module.Repo
;
import
com.topjohnwu.magisk.module.RepoHelper
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.magisk.utils.lib
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.net.URI
;
import
java.net.URISyntaxException
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.List
;
import
java.util.regex.Pattern
;
import
butterknife.BindView
;
import
butterknife.ButterKnife
;
...
...
@@ -44,9 +50,7 @@ public class ModulesFragment extends Fragment {
public
static
List
<
Module
>
listModules
=
new
ArrayList
<>();
public
static
List
<
Module
>
listModulesCache
=
new
ArrayList
<>();
private
static
final
int
FILE_SELECT_CODE
=
0
;
private
int
viewPagePosition
;
private
static
final
int
RESULT_OK
=
1
;
@BindView
(
R
.
id
.
progressBar
)
ProgressBar
progressBar
;
...
...
@@ -57,6 +61,7 @@ public class ModulesFragment extends Fragment {
@BindView
(
R
.
id
.
tab_layout
)
TabLayout
tabLayout
;
private
RepoHelper
.
TaskDelegate
mTaskDelegate
;
private
static
final
int
RQS_OPEN_DOCUMENT_TREE
=
2
;
@Nullable
@Override
...
...
@@ -64,62 +69,68 @@ public class ModulesFragment extends Fragment {
View
view
=
inflater
.
inflate
(
R
.
layout
.
modules_fragment
,
container
,
false
);
ButterKnife
.
bind
(
this
,
view
);
String
[]
extensions
=
new
String
[
1
];
extensions
[
0
]
=
"zip"
;
fabio
.
setOnClickListener
(
v
->
{
Intent
fileintent
=
new
Intent
(
Intent
.
ACTION_GET_CONTENT
);
fileintent
.
setType
(
"application/zip"
);
startActivityForResult
(
fileintent
,
RQS_OPEN_DOCUMENT_TREE
);
});
new
Utils
.
LoadModules
(
getActivity
(),
false
).
execute
();
SharedPreferences
prefs
=
PreferenceManager
.
getDefaultSharedPreferences
(
getActivity
());
mTaskDelegate
=
result
->
{
if
(
result
.
equals
(
"OK"
))
{
Log
.
d
(
"Magisk"
,
"ModulesFragment: We dun got the result, hur hur."
);
Log
.
d
(
"Magisk"
,
"ModulesFragment: We dun got the result, hur hur."
);
RefreshUI
();
}
};
new
updateUI
().
execute
();
return
view
;
}
@Override
public
void
onCreateOptionsMenu
(
Menu
menu
,
MenuInflater
inflater
)
{
super
.
onCreateOptionsMenu
(
menu
,
inflater
);
inflater
.
inflate
(
R
.
menu
.
menu_module
,
menu
);
fabio
.
setOnClickListener
(
view
->
{
openFilePicker
();
});
public
static
boolean
isExternalStorageDocument
(
Uri
uri
)
{
return
"com.android.externalstorage.documents"
.
equals
(
uri
.
getAuthority
());
}
private
void
openFilePicker
()
{
new
MaterialFilePicker
()
.
withSupportFragment
(
this
)
.
withFilter
(
Pattern
.
compile
(
".*\\.zip$"
))
.
withRequestCode
(
FILE_SELECT_CODE
)
.
withHiddenFiles
(
true
)
.
start
();
}
@Override
public
void
onActivityResult
(
int
requestCode
,
int
resultCode
,
Intent
data
)
{
super
.
onActivityResult
(
requestCode
,
resultCode
,
data
);
Log
.
d
(
"Magisk"
,
"WelcomeActivity: Got an OK result"
+
resultCode
);
if
(
resultCode
==
Activity
.
RESULT_OK
)
{
String
path
=
data
.
getStringExtra
(
FilePickerActivity
.
RESULT_FILE_PATH
);
Log
.
d
(
"Magisk"
,
"ModuleFragment: Got an OK result "
+
path
);
if
(
path
!=
null
)
{
Log
.
d
(
"Path: "
,
path
);
Toast
.
makeText
(
getActivity
(),
"Picked file: "
+
path
,
Toast
.
LENGTH_LONG
).
show
();
// Get the Uri of the selected file
String
filePath
=
data
.
getStringExtra
(
FilePickerActivity
.
RESULT_FILE_PATH
);
Uri
uri
=
Uri
.
parse
(
filePath
);
path
=
uri
.
getPath
();
Log
.
d
(
"Magisk"
,
"ModuleFragment: Got an OK result "
+
filePath
+
" and "
+
uri
.
toString
()
+
" and "
+
path
);
String
fileName
=
uri
.
getLastPathSegment
();
new
Utils
.
FlashZIP
(
getActivity
(),
fileName
,
path
).
execute
();
String
file
=
""
;
if
(
resultCode
==
Activity
.
RESULT_OK
&&
requestCode
==
RQS_OPEN_DOCUMENT_TREE
){
if
(
isExternalStorageDocument
(
data
.
getData
()))
{
final
String
docId
=
DocumentsContract
.
getDocumentId
(
data
.
getData
());
final
String
[]
split
=
docId
.
split
(
":"
);
final
String
type
=
split
[
0
];
if
(
"primary"
.
equalsIgnoreCase
(
type
))
{
file
=
Environment
.
getExternalStorageDirectory
()
+
"/"
+
split
[
1
];
}
// TODO handle non-primary volumes
}
String
shit
=
data
.
getDataString
();
Log
.
d
(
"Magisk"
,
"ModulesFragment: Got a result, "
+
shit
+
" and "
+
data
.
getData
().
getAuthority
()
+
" and "
+
file
);
}
}
@Override
public
void
onCreateOptionsMenu
(
Menu
menu
,
MenuInflater
inflater
)
{
super
.
onCreateOptionsMenu
(
menu
,
inflater
);
inflater
.
inflate
(
R
.
menu
.
menu_module
,
menu
);
}
private
void
RefreshUI
()
{
viewPagePosition
=
tabLayout
.
getSelectedTabPosition
();
listModules
.
clear
();
...
...
@@ -129,8 +140,8 @@ public class ModulesFragment extends Fragment {
tabLayout
.
setupWithViewPager
(
viewPager
);
viewPager
.
setCurrentItem
(
viewPagePosition
);
new
Utils
.
LoadModules
(
getActivity
(),
true
).
execute
();
Collections
.
sort
(
listModules
,
new
CustomComparator
());
Collections
.
sort
(
listModulesCache
,
new
CustomComparator
());
Collections
.
sort
(
listModules
,
new
CustomComparator
());
Collections
.
sort
(
listModulesCache
,
new
CustomComparator
());
new
updateUI
().
execute
();
}
...
...
@@ -210,6 +221,7 @@ public class ModulesFragment extends Fragment {
}
}
}
public
class
CustomComparator
implements
Comparator
<
Module
>
{
@Override
public
int
compare
(
Module
o1
,
Module
o2
)
{
...
...
app/src/main/java/com/topjohnwu/magisk/module/RepoHelper.java
View file @
6a90340b
...
...
@@ -18,6 +18,7 @@ import org.json.JSONObject;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.Calendar
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.Date
;
...
...
@@ -43,6 +44,9 @@ public class RepoHelper {
if
(!
prefs
.
contains
(
"hasCachedRepos"
)
|
refresh
)
{
Log
.
d
(
TAG
,
"RepoHelper: Building from web"
);
new
BuildFromWeb
(
delegate
).
execute
();
SimpleDateFormat
format
=
new
SimpleDateFormat
(
"yyyy-MM-dd'T'HH:mm:ss'Z'"
,
Locale
.
US
);
String
date
=
format
.
format
(
Calendar
.
getInstance
().
getTime
());
prefs
.
edit
().
putString
(
"last_update"
,
date
).
apply
();
}
else
{
Log
.
d
(
TAG
,
"RepoHelper: Building from cache"
);
BuildFromCache
();
...
...
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