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
8e7b8825
Commit
8e7b8825
authored
Aug 03, 2017
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename callbackevents to topic/subscribers
parent
2ecbca30
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
137 additions
and
137 deletions
+137
-137
MagiskFragment.java
app/src/main/java/com/topjohnwu/magisk/MagiskFragment.java
+9
-9
MagiskHideFragment.java
...rc/main/java/com/topjohnwu/magisk/MagiskHideFragment.java
+5
-5
MagiskManager.java
app/src/main/java/com/topjohnwu/magisk/MagiskManager.java
+10
-10
MainActivity.java
app/src/main/java/com/topjohnwu/magisk/MainActivity.java
+5
-5
ModulesFragment.java
app/src/main/java/com/topjohnwu/magisk/ModulesFragment.java
+5
-5
ReposFragment.java
app/src/main/java/com/topjohnwu/magisk/ReposFragment.java
+5
-5
SettingsActivity.java
app/src/main/java/com/topjohnwu/magisk/SettingsActivity.java
+13
-13
ApplicationAdapter.java
...ava/com/topjohnwu/magisk/adapters/ApplicationAdapter.java
+3
-3
CheckUpdates.java
...c/main/java/com/topjohnwu/magisk/asyncs/CheckUpdates.java
+1
-1
LoadModules.java
...rc/main/java/com/topjohnwu/magisk/asyncs/LoadModules.java
+1
-1
UpdateRepos.java
...rc/main/java/com/topjohnwu/magisk/asyncs/UpdateRepos.java
+1
-1
Activity.java
...c/main/java/com/topjohnwu/magisk/components/Activity.java
+5
-5
Fragment.java
...c/main/java/com/topjohnwu/magisk/components/Fragment.java
+5
-5
CallbackEvent.java
...c/main/java/com/topjohnwu/magisk/utils/CallbackEvent.java
+0
-68
Topic.java
app/src/main/java/com/topjohnwu/magisk/utils/Topic.java
+68
-0
Utils.java
app/src/main/java/com/topjohnwu/magisk/utils/Utils.java
+1
-1
No files found.
app/src/main/java/com/topjohnwu/magisk/MagiskFragment.java
View file @
8e7b8825
...
...
@@ -31,8 +31,8 @@ import com.topjohnwu.magisk.components.AlertDialogBuilder;
import
com.topjohnwu.magisk.components.Fragment
;
import
com.topjohnwu.magisk.components.SnackbarMaker
;
import
com.topjohnwu.magisk.receivers.DownloadReceiver
;
import
com.topjohnwu.magisk.utils.CallbackEvent
;
import
com.topjohnwu.magisk.utils.Shell
;
import
com.topjohnwu.magisk.utils.Topic
;
import
com.topjohnwu.magisk.utils.Utils
;
import
java.io.File
;
...
...
@@ -49,7 +49,7 @@ import butterknife.OnClick;
import
butterknife.Unbinder
;
public
class
MagiskFragment
extends
Fragment
implements
CallbackEvent
.
Listen
er
,
SwipeRefreshLayout
.
OnRefreshListener
{
implements
Topic
.
Subscrib
er
,
SwipeRefreshLayout
.
OnRefreshListener
{
public
static
final
String
SHOW_DIALOG
=
"dialog"
;
...
...
@@ -268,8 +268,8 @@ public class MagiskFragment extends Fragment
safetyNetStatusText
.
setText
(
R
.
string
.
safetyNet_check_text
);
magiskManager
.
safetyNetDone
.
isTrigger
ed
=
false
;
magiskManager
.
updateCheckDone
.
isTrigger
ed
=
false
;
magiskManager
.
safetyNetDone
.
hasPublish
ed
=
false
;
magiskManager
.
updateCheckDone
.
hasPublish
ed
=
false
;
magiskManager
.
remoteMagiskVersionString
=
null
;
magiskManager
.
remoteMagiskVersionCode
=
-
1
;
collapse
();
...
...
@@ -283,17 +283,17 @@ public class MagiskFragment extends Fragment
}
@Override
public
void
onT
rigger
(
CallbackEvent
event
)
{
if
(
event
==
magiskManager
.
updateCheckDone
)
{
public
void
onT
opicPublished
(
Topic
topic
)
{
if
(
topic
==
magiskManager
.
updateCheckDone
)
{
updateCheckUI
();
}
else
if
(
event
==
magiskManager
.
safetyNetDone
)
{
}
else
if
(
topic
==
magiskManager
.
safetyNetDone
)
{
updateSafetyNetUI
();
}
}
@Override
public
CallbackEvent
[]
getRegisterEvents
()
{
return
new
CallbackEvent
[]
{
magiskManager
.
updateCheckDone
,
magiskManager
.
safetyNetDone
};
public
Topic
[]
getSubscription
()
{
return
new
Topic
[]
{
magiskManager
.
updateCheckDone
,
magiskManager
.
safetyNetDone
};
}
@Override
...
...
app/src/main/java/com/topjohnwu/magisk/MagiskHideFragment.java
View file @
8e7b8825
...
...
@@ -13,13 +13,13 @@ import android.widget.SearchView;
import
com.topjohnwu.magisk.adapters.ApplicationAdapter
;
import
com.topjohnwu.magisk.components.Fragment
;
import
com.topjohnwu.magisk.utils.
CallbackEvent
;
import
com.topjohnwu.magisk.utils.
Topic
;
import
butterknife.BindView
;
import
butterknife.ButterKnife
;
import
butterknife.Unbinder
;
public
class
MagiskHideFragment
extends
Fragment
implements
CallbackEvent
.
Listen
er
{
public
class
MagiskHideFragment
extends
Fragment
implements
Topic
.
Subscrib
er
{
private
Unbinder
unbinder
;
@BindView
(
R
.
id
.
swipeRefreshLayout
)
SwipeRefreshLayout
mSwipeRefreshLayout
;
...
...
@@ -84,13 +84,13 @@ public class MagiskHideFragment extends Fragment implements CallbackEvent.Listen
}
@Override
public
void
onT
rigger
(
CallbackEvent
event
)
{
public
void
onT
opicPublished
(
Topic
topic
)
{
mSwipeRefreshLayout
.
setRefreshing
(
false
);
appAdapter
.
filter
(
lastFilter
);
}
@Override
public
CallbackEvent
[]
getRegisterEvents
()
{
return
new
CallbackEvent
[]
{
getApplication
().
magiskHideDone
};
public
Topic
[]
getSubscription
()
{
return
new
Topic
[]
{
getApplication
().
magiskHideDone
};
}
}
app/src/main/java/com/topjohnwu/magisk/MagiskManager.java
View file @
8e7b8825
...
...
@@ -16,9 +16,9 @@ import com.topjohnwu.magisk.asyncs.ParallelTask;
import
com.topjohnwu.magisk.database.RepoDatabaseHelper
;
import
com.topjohnwu.magisk.database.SuDatabaseHelper
;
import
com.topjohnwu.magisk.module.Module
;
import
com.topjohnwu.magisk.utils.CallbackEvent
;
import
com.topjohnwu.magisk.utils.SafetyNetHelper
;
import
com.topjohnwu.magisk.utils.Shell
;
import
com.topjohnwu.magisk.utils.Topic
;
import
com.topjohnwu.magisk.utils.Utils
;
import
java.io.File
;
...
...
@@ -43,14 +43,14 @@ public class MagiskManager extends Application {
public
static
final
String
BUSYBOX_ARM
=
"https://github.com/topjohnwu/ndk-busybox/releases/download/1.27.1/busybox-arm"
;
public
static
final
String
BUSYBOX_X86
=
"https://github.com/topjohnwu/ndk-busybox/releases/download/1.27.1/busybox-x86"
;
//
Event
s
public
final
CallbackEvent
magiskHideDone
=
new
CallbackEvent
();
public
final
CallbackEvent
reloadActivity
=
new
CallbackEvent
();
public
final
CallbackEvent
moduleLoadDone
=
new
CallbackEvent
();
public
final
CallbackEvent
repoLoadDone
=
new
CallbackEvent
();
public
final
CallbackEvent
updateCheckDone
=
new
CallbackEvent
();
public
final
CallbackEvent
safetyNetDone
=
new
CallbackEvent
();
public
final
CallbackEvent
localeDone
=
new
CallbackEvent
();
//
Topic
s
public
final
Topic
magiskHideDone
=
new
Topic
();
public
final
Topic
reloadActivity
=
new
Topic
();
public
final
Topic
moduleLoadDone
=
new
Topic
();
public
final
Topic
repoLoadDone
=
new
Topic
();
public
final
Topic
updateCheckDone
=
new
Topic
();
public
final
Topic
safetyNetDone
=
new
Topic
();
public
final
Topic
localeDone
=
new
Topic
();
// Info
public
String
magiskVersionString
;
...
...
@@ -113,7 +113,7 @@ public class MagiskManager extends Application {
@Override
protected
void
onPostExecute
(
Void
aVoid
)
{
getMagiskManager
().
localeDone
.
trigger
();
getMagiskManager
().
localeDone
.
publish
();
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/MainActivity.java
View file @
8e7b8825
...
...
@@ -20,15 +20,15 @@ import android.view.MenuItem;
import
android.view.View
;
import
com.topjohnwu.magisk.components.Activity
;
import
com.topjohnwu.magisk.utils.CallbackEvent
;
import
com.topjohnwu.magisk.utils.Shell
;
import
com.topjohnwu.magisk.utils.Topic
;
import
com.topjohnwu.magisk.utils.Utils
;
import
butterknife.BindView
;
import
butterknife.ButterKnife
;
public
class
MainActivity
extends
Activity
implements
NavigationView
.
OnNavigationItemSelectedListener
,
CallbackEvent
.
Listen
er
{
implements
NavigationView
.
OnNavigationItemSelectedListener
,
Topic
.
Subscrib
er
{
private
final
Handler
mDrawerHandler
=
new
Handler
();
private
SharedPreferences
prefs
;
...
...
@@ -110,13 +110,13 @@ public class MainActivity extends Activity
}
@Override
public
void
onT
rigger
(
CallbackEvent
event
)
{
public
void
onT
opicPublished
(
Topic
topic
)
{
recreate
();
}
@Override
public
CallbackEvent
[]
getRegisterEvents
()
{
return
new
CallbackEvent
[]
{
getApplicationContext
().
reloadActivity
};
public
Topic
[]
getSubscription
()
{
return
new
Topic
[]
{
getApplicationContext
().
reloadActivity
};
}
public
void
checkHideSection
()
{
...
...
app/src/main/java/com/topjohnwu/magisk/ModulesFragment.java
View file @
8e7b8825
...
...
@@ -16,8 +16,8 @@ import com.topjohnwu.magisk.adapters.ModulesAdapter;
import
com.topjohnwu.magisk.asyncs.LoadModules
;
import
com.topjohnwu.magisk.components.Fragment
;
import
com.topjohnwu.magisk.module.Module
;
import
com.topjohnwu.magisk.utils.CallbackEvent
;
import
com.topjohnwu.magisk.utils.Logger
;
import
com.topjohnwu.magisk.utils.Topic
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -26,7 +26,7 @@ import butterknife.BindView;
import
butterknife.ButterKnife
;
import
butterknife.Unbinder
;
public
class
ModulesFragment
extends
Fragment
implements
CallbackEvent
.
Listen
er
{
public
class
ModulesFragment
extends
Fragment
implements
Topic
.
Subscrib
er
{
private
static
final
int
FETCH_ZIP_CODE
=
2
;
...
...
@@ -73,14 +73,14 @@ public class ModulesFragment extends Fragment implements CallbackEvent.Listener
}
@Override
public
void
onT
rigger
(
CallbackEvent
event
)
{
public
void
onT
opicPublished
(
Topic
topic
)
{
Logger
.
dev
(
"ModulesFragment: UI refresh triggered"
);
updateUI
();
}
@Override
public
CallbackEvent
[]
getRegisterEvents
()
{
return
new
CallbackEvent
[]
{
getApplication
().
moduleLoadDone
};
public
Topic
[]
getSubscription
()
{
return
new
Topic
[]
{
getApplication
().
moduleLoadDone
};
}
@Override
...
...
app/src/main/java/com/topjohnwu/magisk/ReposFragment.java
View file @
8e7b8825
...
...
@@ -15,14 +15,14 @@ import android.widget.TextView;
import
com.topjohnwu.magisk.adapters.ReposAdapter
;
import
com.topjohnwu.magisk.asyncs.UpdateRepos
;
import
com.topjohnwu.magisk.components.Fragment
;
import
com.topjohnwu.magisk.utils.CallbackEvent
;
import
com.topjohnwu.magisk.utils.Logger
;
import
com.topjohnwu.magisk.utils.Topic
;
import
butterknife.BindView
;
import
butterknife.ButterKnife
;
import
butterknife.Unbinder
;
public
class
ReposFragment
extends
Fragment
implements
CallbackEvent
.
Listen
er
{
public
class
ReposFragment
extends
Fragment
implements
Topic
.
Subscrib
er
{
private
Unbinder
unbinder
;
@BindView
(
R
.
id
.
recyclerView
)
RecyclerView
recyclerView
;
...
...
@@ -59,7 +59,7 @@ public class ReposFragment extends Fragment implements CallbackEvent.Listener {
}
@Override
public
void
onT
rigger
(
CallbackEvent
event
)
{
public
void
onT
opicPublished
(
Topic
topic
)
{
Logger
.
dev
(
"ReposFragment: UI refresh triggered"
);
mSwipeRefreshLayout
.
setRefreshing
(
false
);
adapter
.
notifyDBChanged
();
...
...
@@ -68,8 +68,8 @@ public class ReposFragment extends Fragment implements CallbackEvent.Listener {
}
@Override
public
CallbackEvent
[]
getRegisterEvents
()
{
return
new
CallbackEvent
[]
{
getApplication
().
repoLoadDone
};
public
Topic
[]
getSubscription
()
{
return
new
Topic
[]
{
getApplication
().
repoLoadDone
};
}
@Override
...
...
app/src/main/java/com/topjohnwu/magisk/SettingsActivity.java
View file @
8e7b8825
...
...
@@ -15,9 +15,9 @@ import android.widget.Toast;
import
com.topjohnwu.magisk.components.Activity
;
import
com.topjohnwu.magisk.database.SuDatabaseHelper
;
import
com.topjohnwu.magisk.utils.CallbackEvent
;
import
com.topjohnwu.magisk.utils.Logger
;
import
com.topjohnwu.magisk.utils.Shell
;
import
com.topjohnwu.magisk.utils.Topic
;
import
com.topjohnwu.magisk.utils.Utils
;
import
java.util.Locale
;
...
...
@@ -25,7 +25,7 @@ import java.util.Locale;
import
butterknife.BindView
;
import
butterknife.ButterKnife
;
public
class
SettingsActivity
extends
Activity
implements
CallbackEvent
.
Listen
er
{
public
class
SettingsActivity
extends
Activity
implements
Topic
.
Subscrib
er
{
@BindView
(
R
.
id
.
toolbar
)
Toolbar
toolbar
;
...
...
@@ -58,18 +58,18 @@ public class SettingsActivity extends Activity implements CallbackEvent.Listener
}
@Override
public
void
onT
rigger
(
CallbackEvent
event
)
{
public
void
onT
opicPublished
(
Topic
topic
)
{
recreate
();
}
@Override
public
CallbackEvent
[]
getRegisterEvents
()
{
return
new
CallbackEvent
[]
{
getApplicationContext
().
reloadActivity
};
public
Topic
[]
getSubscription
()
{
return
new
Topic
[]
{
getApplicationContext
().
reloadActivity
};
}
public
static
class
SettingsFragment
extends
PreferenceFragment
implements
SharedPreferences
.
OnSharedPreferenceChangeListener
,
CallbackEvent
.
Listen
er
{
Topic
.
Subscrib
er
{
private
SharedPreferences
prefs
;
private
PreferenceScreen
prefScreen
;
...
...
@@ -162,13 +162,13 @@ public class SettingsActivity extends Activity implements CallbackEvent.Listener
public
void
onResume
()
{
super
.
onResume
();
prefs
.
registerOnSharedPreferenceChangeListener
(
this
);
registerEvent
s
();
subscribeTopic
s
();
}
@Override
public
void
onPause
()
{
prefs
.
unregisterOnSharedPreferenceChangeListener
(
this
);
un
registerEvent
s
();
un
subscribeTopic
s
();
super
.
onPause
();
}
...
...
@@ -182,7 +182,7 @@ public class SettingsActivity extends Activity implements CallbackEvent.Listener
enabled
=
prefs
.
getBoolean
(
"dark_theme"
,
false
);
if
(
magiskManager
.
isDarkTheme
!=
enabled
)
{
magiskManager
.
isDarkTheme
=
enabled
;
magiskManager
.
reloadActivity
.
trigger
(
false
);
magiskManager
.
reloadActivity
.
publish
(
false
);
}
break
;
case
"disable"
:
...
...
@@ -243,7 +243,7 @@ public class SettingsActivity extends Activity implements CallbackEvent.Listener
break
;
case
"locale"
:
magiskManager
.
setLocale
();
magiskManager
.
reloadActivity
.
trigger
(
false
);
magiskManager
.
reloadActivity
.
publish
(
false
);
break
;
}
setSummary
();
...
...
@@ -265,13 +265,13 @@ public class SettingsActivity extends Activity implements CallbackEvent.Listener
}
@Override
public
void
onT
rigger
(
CallbackEvent
event
)
{
public
void
onT
opicPublished
(
Topic
topic
)
{
setLocalePreference
((
ListPreference
)
findPreference
(
"locale"
));
}
@Override
public
CallbackEvent
[]
getRegisterEvents
()
{
return
new
CallbackEvent
[]
{
magiskManager
.
localeDone
};
public
Topic
[]
getSubscription
()
{
return
new
Topic
[]
{
magiskManager
.
localeDone
};
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/adapters/ApplicationAdapter.java
View file @
8e7b8825
...
...
@@ -16,8 +16,8 @@ import android.widget.TextView;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.asyncs.ParallelTask
;
import
com.topjohnwu.magisk.components.SnackbarMaker
;
import
com.topjohnwu.magisk.utils.CallbackEvent
;
import
com.topjohnwu.magisk.utils.Shell
;
import
com.topjohnwu.magisk.utils.Topic
;
import
com.topjohnwu.magisk.utils.Utils
;
import
java.util.ArrayList
;
...
...
@@ -46,7 +46,7 @@ public class ApplicationAdapter extends RecyclerView.Adapter<ApplicationAdapter.
private
List
<
String
>
mHideList
;
private
PackageManager
pm
;
private
ApplicationFilter
filter
;
private
CallbackEvent
magiskHideDone
;
private
Topic
magiskHideDone
;
private
Shell
shell
;
public
ApplicationAdapter
(
Context
context
)
{
...
...
@@ -169,7 +169,7 @@ public class ApplicationAdapter extends RecyclerView.Adapter<ApplicationAdapter.
@Override
protected
void
onPostExecute
(
Void
v
)
{
magiskHideDone
.
trigger
(
false
);
magiskHideDone
.
publish
(
false
);
}
}
}
app/src/main/java/com/topjohnwu/magisk/asyncs/CheckUpdates.java
View file @
8e7b8825
...
...
@@ -56,7 +56,7 @@ public class CheckUpdates extends ParallelTask<Void, Void, Void> {
Utils
.
showMagiskUpdate
(
magiskManager
);
}
}
magiskManager
.
updateCheckDone
.
trigger
();
magiskManager
.
updateCheckDone
.
publish
();
super
.
onPostExecute
(
v
);
}
}
app/src/main/java/com/topjohnwu/magisk/asyncs/LoadModules.java
View file @
8e7b8825
...
...
@@ -39,7 +39,7 @@ public class LoadModules extends ParallelTask<Void, Void, Void> {
protected
void
onPostExecute
(
Void
v
)
{
MagiskManager
magiskManager
=
getMagiskManager
();
if
(
magiskManager
==
null
)
return
;
magiskManager
.
moduleLoadDone
.
trigger
();
magiskManager
.
moduleLoadDone
.
publish
();
super
.
onPostExecute
(
v
);
}
}
app/src/main/java/com/topjohnwu/magisk/asyncs/UpdateRepos.java
View file @
8e7b8825
...
...
@@ -186,7 +186,7 @@ public class UpdateRepos extends ParallelTask<Void, Void, Void> {
protected
void
onPostExecute
(
Void
v
)
{
MagiskManager
magiskManager
=
getMagiskManager
();
if
(
magiskManager
==
null
)
return
;
magiskManager
.
repoLoadDone
.
trigger
();
magiskManager
.
repoLoadDone
.
publish
();
super
.
onPostExecute
(
v
);
}
}
app/src/main/java/com/topjohnwu/magisk/components/Activity.java
View file @
8e7b8825
...
...
@@ -8,7 +8,7 @@ import android.view.WindowManager;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.utils.
CallbackEvent
;
import
com.topjohnwu.magisk.utils.
Topic
;
public
class
Activity
extends
AppCompatActivity
{
...
...
@@ -22,15 +22,15 @@ public class Activity extends AppCompatActivity {
@Override
protected
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
if
(
this
instanceof
CallbackEvent
.
Listen
er
)
{
((
CallbackEvent
.
Listener
)
this
).
registerEvent
s
();
if
(
this
instanceof
Topic
.
Subscrib
er
)
{
((
Topic
.
Subscriber
)
this
).
subscribeTopic
s
();
}
}
@Override
protected
void
onDestroy
()
{
if
(
this
instanceof
CallbackEvent
.
Listen
er
)
{
((
CallbackEvent
.
Listener
)
this
).
unregisterEvent
s
();
if
(
this
instanceof
Topic
.
Subscrib
er
)
{
((
Topic
.
Subscriber
)
this
).
unsubscribeTopic
s
();
}
super
.
onDestroy
();
}
...
...
app/src/main/java/com/topjohnwu/magisk/components/Fragment.java
View file @
8e7b8825
package
com
.
topjohnwu
.
magisk
.
components
;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.utils.
CallbackEvent
;
import
com.topjohnwu.magisk.utils.
Topic
;
import
com.topjohnwu.magisk.utils.Utils
;
public
class
Fragment
extends
android
.
support
.
v4
.
app
.
Fragment
{
...
...
@@ -13,15 +13,15 @@ public class Fragment extends android.support.v4.app.Fragment {
@Override
public
void
onResume
()
{
super
.
onResume
();
if
(
this
instanceof
CallbackEvent
.
Listen
er
)
{
((
CallbackEvent
.
Listener
)
this
).
registerEvent
s
();
if
(
this
instanceof
Topic
.
Subscrib
er
)
{
((
Topic
.
Subscriber
)
this
).
subscribeTopic
s
();
}
}
@Override
public
void
onPause
()
{
if
(
this
instanceof
CallbackEvent
.
Listen
er
)
{
((
CallbackEvent
.
Listener
)
this
).
unregisterEvent
s
();
if
(
this
instanceof
Topic
.
Subscrib
er
)
{
((
Topic
.
Subscriber
)
this
).
unsubscribeTopic
s
();
}
super
.
onPause
();
}
...
...
app/src/main/java/com/topjohnwu/magisk/utils/CallbackEvent.java
deleted
100644 → 0
View file @
2ecbca30
package
com
.
topjohnwu
.
magisk
.
utils
;
import
java.lang.ref.WeakReference
;
import
java.util.Iterator
;
import
java.util.LinkedList
;
import
java.util.List
;
public
class
CallbackEvent
{
public
boolean
isTriggered
=
false
;
private
List
<
WeakReference
<
Listener
>>
listeners
;
public
void
register
(
Listener
l
)
{
if
(
listeners
==
null
)
{
listeners
=
new
LinkedList
<>();
}
listeners
.
add
(
new
WeakReference
<>(
l
));
}
public
void
unregister
()
{
listeners
=
null
;
}
public
void
unregister
(
Listener
l
)
{
for
(
Iterator
<
WeakReference
<
Listener
>>
i
=
listeners
.
iterator
();
i
.
hasNext
();)
{
WeakReference
<
Listener
>
listener
=
i
.
next
();
if
(
listener
.
get
()
==
null
||
listener
.
get
()
==
l
)
{
i
.
remove
();
}
}
}
public
void
trigger
()
{
trigger
(
true
);
}
public
void
trigger
(
boolean
b
)
{
isTriggered
=
b
;
if
(
listeners
!=
null
)
{
for
(
WeakReference
<
Listener
>
listener
:
listeners
)
{
if
(
listener
.
get
()
!=
null
)
listener
.
get
().
onTrigger
(
this
);
}
}
}
public
interface
Listener
{
default
void
registerEvents
()
{
for
(
CallbackEvent
event
:
getRegisterEvents
())
{
if
(
event
.
isTriggered
)
{
onTrigger
(
event
);
}
event
.
register
(
this
);
}
}
default
void
unregisterEvents
()
{
for
(
CallbackEvent
event
:
getRegisterEvents
())
{
event
.
unregister
(
this
);
}
}
default
void
onTrigger
()
{
onTrigger
(
null
);
}
void
onTrigger
(
CallbackEvent
event
);
CallbackEvent
[]
getRegisterEvents
();
}
}
app/src/main/java/com/topjohnwu/magisk/utils/Topic.java
0 → 100644
View file @
8e7b8825
package
com
.
topjohnwu
.
magisk
.
utils
;
import
java.lang.ref.WeakReference
;
import
java.util.Iterator
;
import
java.util.LinkedList
;
import
java.util.List
;
public
class
Topic
{
public
boolean
hasPublished
=
false
;
private
List
<
WeakReference
<
Subscriber
>>
subscribers
;
public
void
subscribe
(
Subscriber
sub
)
{
if
(
subscribers
==
null
)
{
subscribers
=
new
LinkedList
<>();
}
subscribers
.
add
(
new
WeakReference
<>(
sub
));
}
public
void
unsubscribe
()
{
subscribers
=
null
;
}
public
void
unsubscribe
(
Subscriber
sub
)
{
for
(
Iterator
<
WeakReference
<
Subscriber
>>
i
=
subscribers
.
iterator
();
i
.
hasNext
();)
{
WeakReference
<
Subscriber
>
subscriber
=
i
.
next
();
if
(
subscriber
.
get
()
==
null
||
subscriber
.
get
()
==
sub
)
{
i
.
remove
();
}
}
}
public
void
publish
()
{
publish
(
true
);
}
public
void
publish
(
boolean
b
)
{
hasPublished
=
b
;
if
(
subscribers
!=
null
)
{
for
(
WeakReference
<
Subscriber
>
subscriber
:
subscribers
)
{
if
(
subscriber
.
get
()
!=
null
)
subscriber
.
get
().
onTopicPublished
(
this
);
}
}
}
public
interface
Subscriber
{
default
void
subscribeTopics
()
{
for
(
Topic
topic
:
getSubscription
())
{
if
(
topic
.
hasPublished
)
{
onTopicPublished
(
topic
);
}
topic
.
subscribe
(
this
);
}
}
default
void
unsubscribeTopics
()
{
for
(
Topic
event
:
getSubscription
())
{
event
.
unsubscribe
(
this
);
}
}
default
void
onTopicPublished
()
{
onTopicPublished
(
null
);
}
void
onTopicPublished
(
Topic
topic
);
Topic
[]
getSubscription
();
}
}
app/src/main/java/com/topjohnwu/magisk/utils/Utils.java
View file @
8e7b8825
...
...
@@ -140,7 +140,7 @@ public class Utils {
@Override
public
void
handleResults
(
Result
result
)
{
getMagiskManager
(
mActivity
).
SNCheckResult
=
result
;
getMagiskManager
(
mActivity
).
safetyNetDone
.
trigger
();
getMagiskManager
(
mActivity
).
safetyNetDone
.
publish
();
}
}.
requestTest
();
}
...
...
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