@@ -29,7 +29,7 @@ import androidx.core.content.ContextCompat
29
29
import androidx.preference.PreferenceManager
30
30
31
31
32
- class MainActivity : ComponentActivity (), SharedPreferences.OnSharedPreferenceChangeListener {
32
+ class MainActivity : ComponentActivity (), SharedPreferences.OnSharedPreferenceChangeListener {
33
33
private var filePathCallback: ValueCallback <Array <Uri >>? = null
34
34
35
35
class AndroidJSInterface (private val preference_button : Button ) {
@@ -62,7 +62,7 @@ class MainActivity : ComponentActivity(), SharedPreferences.OnSharedPreferenceCh
62
62
val getFile = registerForActivityResult(ActivityResultContracts .StartActivityForResult ()) {
63
63
if (it.resultCode == Activity .RESULT_CANCELED ) {
64
64
filePathCallback?.onReceiveValue(null )
65
- } else if (it.resultCode == Activity .RESULT_OK && filePathCallback != null ){
65
+ } else if (it.resultCode == Activity .RESULT_OK && filePathCallback != null ) {
66
66
filePathCallback!! .onReceiveValue(
67
67
WebChromeClient .FileChooserParams .parseResult(it.resultCode, it.data)
68
68
)
@@ -71,8 +71,8 @@ class MainActivity : ComponentActivity(), SharedPreferences.OnSharedPreferenceCh
71
71
}
72
72
}
73
73
74
- private fun updateBrowser (webView : WebView , preferences : SharedPreferences ){
75
- if (preferences.all.getValue(" use_followed_feed" ) as Boolean ){
74
+ private fun updateBrowser (webView : WebView , preferences : SharedPreferences ) {
75
+ if (preferences.all.getValue(" use_followed_feed" ) as Boolean ) {
76
76
webView.loadUrl(" https://www.instagram.com/?variant=following" )
77
77
} else {
78
78
webView.loadUrl(" https://www.instagram.com/" )
@@ -96,10 +96,9 @@ class MainActivity : ComponentActivity(), SharedPreferences.OnSharedPreferenceCh
96
96
if (line.startsWith(" /**" )) {
97
97
// Using the space to split the element and to find out its identifier e.g REEL_FEED
98
98
val identifier = line.split(" " ).toTypedArray()[1 ]
99
- Log .d(" InjectionCompiler" , identifier)
100
99
101
100
// No lines till the next identifier
102
- if (identifier == " END" ) {
101
+ if (identifier == " END" ) {
103
102
add_future_lines = false
104
103
}
105
104
@@ -112,14 +111,14 @@ class MainActivity : ComponentActivity(), SharedPreferences.OnSharedPreferenceCh
112
111
else {
113
112
val state = preferences?.all?.getValue(identifier) as Boolean
114
113
// On true execute
115
- if (identifier == " use_followed_feed" ){
116
- if (state){
114
+ if (identifier == " use_followed_feed" ) {
115
+ if (state) {
117
116
add_future_lines = true
118
117
}
119
118
}
120
119
// On false execute
121
120
else {
122
- if (! state){
121
+ if (! state) {
123
122
add_future_lines = true
124
123
}
125
124
}
@@ -128,8 +127,8 @@ class MainActivity : ComponentActivity(), SharedPreferences.OnSharedPreferenceCh
128
127
// Normal content to be added
129
128
else {
130
129
// Checking if this content line (no identifier) should be added
131
- if (add_future_lines && line != " " ){
132
- injector_string + = line
130
+ if (add_future_lines && line != " " ) {
131
+ injector_string + = line.trim()
133
132
}
134
133
}
135
134
}
@@ -147,7 +146,11 @@ class MainActivity : ComponentActivity(), SharedPreferences.OnSharedPreferenceCh
147
146
val readExternalStorage = Manifest .permission.READ_EXTERNAL_STORAGE
148
147
149
148
// readExternalStorage
150
- if (! (ContextCompat .checkSelfPermission(this , readExternalStorage) == PackageManager .PERMISSION_GRANTED )){
149
+ if (! (ContextCompat .checkSelfPermission(
150
+ this ,
151
+ readExternalStorage
152
+ ) == PackageManager .PERMISSION_GRANTED )
153
+ ) {
151
154
ActivityCompat .requestPermissions(this , arrayOf(readExternalStorage), 23 )
152
155
}
153
156
@@ -176,7 +179,10 @@ class MainActivity : ComponentActivity(), SharedPreferences.OnSharedPreferenceCh
176
179
177
180
webView.webChromeClient = object : WebChromeClient () {
178
181
override fun onConsoleMessage (consoleMessage : ConsoleMessage ): Boolean {
179
- Log .d(" WebInternal" , " ${consoleMessage.message()} -- Line: ${consoleMessage.lineNumber()} of ${consoleMessage.sourceId()} " )
182
+ Log .d(
183
+ " WebInternal" ,
184
+ " ${consoleMessage.message()} -- Line: ${consoleMessage.lineNumber()} of ${consoleMessage.sourceId()} "
185
+ )
180
186
return true
181
187
}
182
188
@@ -202,8 +208,7 @@ class MainActivity : ComponentActivity(), SharedPreferences.OnSharedPreferenceCh
202
208
}
203
209
}
204
210
205
- fun injectJS (webview : WebView ? ){
206
- Log .d(" WebInternal" , " INJECTION" )
211
+ fun injectJS (webview : WebView ? ) {
207
212
webview?.loadUrl(" javascript:(function f(){${injector_content} })()" )
208
213
}
209
214
@@ -219,17 +224,15 @@ class MainActivity : ComponentActivity(), SharedPreferences.OnSharedPreferenceCh
219
224
// Injection if the page is fully loaded
220
225
webView.webViewClient = object : WebViewClient () {
221
226
override fun onPageFinished (view : WebView ? , url : String? ) {
222
- injectJS(view);
227
+ injectJS(view)
223
228
super .onPageFinished(view, url)
224
229
}
225
230
}
226
231
227
-
228
-
229
- onBackPressedDispatcher.addCallback(object : OnBackPressedCallback (true ){
232
+ onBackPressedDispatcher.addCallback(object : OnBackPressedCallback (true ) {
230
233
override fun handleOnBackPressed () {
231
- if (webView.canGoBack()){
232
- webView.goBack();
234
+ if (webView.canGoBack()) {
235
+ webView.goBack()
233
236
}
234
237
}
235
238
})
0 commit comments