Skip to content

Commit 5382d52

Browse files
committed
cleaning the code
1 parent 06ae61f commit 5382d52

File tree

3 files changed

+26
-31
lines changed

3 files changed

+26
-31
lines changed

app/src/main/java/com/example/noreel/MainActivity.kt

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import androidx.core.content.ContextCompat
2929
import androidx.preference.PreferenceManager
3030

3131

32-
class MainActivity : ComponentActivity(), SharedPreferences.OnSharedPreferenceChangeListener {
32+
class MainActivity : ComponentActivity(), SharedPreferences.OnSharedPreferenceChangeListener {
3333
private var filePathCallback: ValueCallback<Array<Uri>>? = null
3434

3535
class AndroidJSInterface(private val preference_button: Button) {
@@ -62,7 +62,7 @@ class MainActivity : ComponentActivity(), SharedPreferences.OnSharedPreferenceCh
6262
val getFile = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
6363
if (it.resultCode == Activity.RESULT_CANCELED) {
6464
filePathCallback?.onReceiveValue(null)
65-
} else if (it.resultCode == Activity.RESULT_OK && filePathCallback != null){
65+
} else if (it.resultCode == Activity.RESULT_OK && filePathCallback != null) {
6666
filePathCallback!!.onReceiveValue(
6767
WebChromeClient.FileChooserParams.parseResult(it.resultCode, it.data)
6868
)
@@ -71,8 +71,8 @@ class MainActivity : ComponentActivity(), SharedPreferences.OnSharedPreferenceCh
7171
}
7272
}
7373

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) {
7676
webView.loadUrl("https://www.instagram.com/?variant=following")
7777
} else {
7878
webView.loadUrl("https://www.instagram.com/")
@@ -96,10 +96,9 @@ class MainActivity : ComponentActivity(), SharedPreferences.OnSharedPreferenceCh
9696
if (line.startsWith("/**")) {
9797
//Using the space to split the element and to find out its identifier e.g REEL_FEED
9898
val identifier = line.split(" ").toTypedArray()[1]
99-
Log.d("InjectionCompiler", identifier)
10099

101100
// No lines till the next identifier
102-
if(identifier == "END") {
101+
if (identifier == "END") {
103102
add_future_lines = false
104103
}
105104

@@ -112,14 +111,14 @@ class MainActivity : ComponentActivity(), SharedPreferences.OnSharedPreferenceCh
112111
else {
113112
val state = preferences?.all?.getValue(identifier) as Boolean
114113
// On true execute
115-
if(identifier == "use_followed_feed"){
116-
if(state){
114+
if (identifier == "use_followed_feed") {
115+
if (state) {
117116
add_future_lines = true
118117
}
119118
}
120119
// On false execute
121120
else {
122-
if(!state){
121+
if (!state) {
123122
add_future_lines = true
124123
}
125124
}
@@ -128,8 +127,8 @@ class MainActivity : ComponentActivity(), SharedPreferences.OnSharedPreferenceCh
128127
// Normal content to be added
129128
else {
130129
// 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()
133132
}
134133
}
135134
}
@@ -147,7 +146,11 @@ class MainActivity : ComponentActivity(), SharedPreferences.OnSharedPreferenceCh
147146
val readExternalStorage = Manifest.permission.READ_EXTERNAL_STORAGE
148147

149148
// readExternalStorage
150-
if(!(ContextCompat.checkSelfPermission(this, readExternalStorage) == PackageManager.PERMISSION_GRANTED)){
149+
if (!(ContextCompat.checkSelfPermission(
150+
this,
151+
readExternalStorage
152+
) == PackageManager.PERMISSION_GRANTED)
153+
) {
151154
ActivityCompat.requestPermissions(this, arrayOf(readExternalStorage), 23)
152155
}
153156

@@ -176,7 +179,10 @@ class MainActivity : ComponentActivity(), SharedPreferences.OnSharedPreferenceCh
176179

177180
webView.webChromeClient = object : WebChromeClient() {
178181
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+
)
180186
return true
181187
}
182188

@@ -202,8 +208,7 @@ class MainActivity : ComponentActivity(), SharedPreferences.OnSharedPreferenceCh
202208
}
203209
}
204210

205-
fun injectJS(webview: WebView?){
206-
Log.d("WebInternal", "INJECTION")
211+
fun injectJS(webview: WebView?) {
207212
webview?.loadUrl("javascript:(function f(){${injector_content}})()")
208213
}
209214

@@ -219,17 +224,15 @@ class MainActivity : ComponentActivity(), SharedPreferences.OnSharedPreferenceCh
219224
//Injection if the page is fully loaded
220225
webView.webViewClient = object : WebViewClient() {
221226
override fun onPageFinished(view: WebView?, url: String?) {
222-
injectJS(view);
227+
injectJS(view)
223228
super.onPageFinished(view, url)
224229
}
225230
}
226231

227-
228-
229-
onBackPressedDispatcher.addCallback(object: OnBackPressedCallback(true){
232+
onBackPressedDispatcher.addCallback(object : OnBackPressedCallback(true) {
230233
override fun handleOnBackPressed() {
231-
if(webView.canGoBack()){
232-
webView.goBack();
234+
if (webView.canGoBack()) {
235+
webView.goBack()
233236
}
234237
}
235238
})

app/src/main/java/com/example/noreel/SettingsActivity.kt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.example.noreel
22

33
import android.os.Bundle
4-
import android.util.Log
54
import androidx.appcompat.app.AppCompatActivity
65
import androidx.preference.PreferenceFragmentCompat
76

@@ -14,13 +13,6 @@ class SettingsActivity : AppCompatActivity() {
1413
.replace(R.id.SettingsFragmentContainerView, SettingsFragment())
1514
.commit()
1615
}
17-
18-
override fun onStop() {
19-
20-
super.onStop()
21-
setResult(RESULT_OK)
22-
finish()
23-
}
2416
}
2517

2618
class SettingsFragment : PreferenceFragmentCompat() {

app/src/main/res/xml/preferences.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
<SwitchPreference
1818
android:title="Reel feed"
1919
android:key="reel_feed"
20-
android:summary="This feature disables the Reel feed but not Reels itself."
20+
android:summary="The feed where short videos / reels are played"
2121
android:defaultValue="false" />
2222
<SwitchPreference
2323
android:title="Explore feed"
2424
android:key="search_feed"
25-
android:summary="The feed under the search bar when clicking at the search icon."
25+
android:summary="The explore feed under the search bar when clicking at the search icon."
2626
android:defaultValue="true" />
2727
</PreferenceCategory>
2828
<PreferenceCategory android:title="Content Settings">

0 commit comments

Comments
 (0)