Skip to content

Commit 6b72000

Browse files
Feat: Added the base for the new settings screen (#130)
* Feat: Added the base for the new settings screen * Fix: Removed junk from Home * Fix: Cleanup Setting * Fix: Bit more advanced settings Signed-off-by: HeCodes2Much <[email protected]>
1 parent 9601afa commit 6b72000

32 files changed

+2449
-1448
lines changed

app/build.gradle.kts

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,25 @@ android {
7878
manifestPlaceholders["coarseLocationPermission"] =
7979
"android.permission.ACCESS_COARSE_LOCATION"
8080
val weatherFile = project.rootProject.file("weather.properties")
81-
val properties = Properties()
82-
properties.load(weatherFile.inputStream())
83-
val apiKey = properties.getProperty("WEATHER_API_KEY") ?: ""
84-
buildConfigField(
85-
type = "String",
86-
name = "API_KEY",
87-
value = "\"$apiKey\""
88-
)
81+
if (weatherFile.exists()) {
82+
val properties = Properties()
83+
weatherFile.inputStream().use { inputStream ->
84+
properties.load(inputStream)
85+
}
86+
val apiKey = properties.getProperty("WEATHER_API_KEY") ?: ""
87+
buildConfigField(
88+
type = "String",
89+
name = "API_KEY",
90+
value = "\"$apiKey\""
91+
)
92+
} else {
93+
buildConfigField(
94+
type = "String",
95+
name = "API_KEY",
96+
value = "\"REMOVE\""
97+
)
98+
println("weather.properties file not found.")
99+
}
89100
}
90101

91102
create("withoutInternet") {
@@ -105,16 +116,27 @@ android {
105116
applicationIdSuffix = ".nightly"
106117
versionNameSuffix = "-nightly"
107118
manifestPlaceholders["internetPermission"] = "android.permission.INTERNET"
108-
val weatherFile = project.rootProject.file("weather.properties")
109-
val properties = Properties()
110-
properties.load(weatherFile.inputStream())
111-
val apiKey = properties.getProperty("WEATHER_API_KEY") ?: ""
112-
buildConfigField(
113-
type = "String",
114-
name = "API_KEY",
115-
value = "\"$apiKey\""
116-
)
117119
resValue("string", "app_name", "Easy Launcher (Nightly)")
120+
val weatherFile = project.rootProject.file("weather.properties")
121+
if (weatherFile.exists()) {
122+
val properties = Properties()
123+
weatherFile.inputStream().use { inputStream ->
124+
properties.load(inputStream)
125+
}
126+
val apiKey = properties.getProperty("WEATHER_API_KEY") ?: ""
127+
buildConfigField(
128+
type = "String",
129+
name = "API_KEY",
130+
value = "\"$apiKey\""
131+
)
132+
} else {
133+
buildConfigField(
134+
type = "String",
135+
name = "API_KEY",
136+
value = "\"REMOVE\""
137+
)
138+
println("weather.properties file not found.")
139+
}
118140
}
119141

120142
create("withoutInternetNightly") {

app/src/main/java/com/github/droidworksstudio/launcher/helper/AppHelper.kt

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import android.content.res.Configuration
1010
import android.content.res.Resources
1111
import android.net.Uri
1212
import android.os.Build
13+
import android.util.Log
1314
import android.view.Gravity
1415
import android.view.View
1516
import android.view.Window
@@ -19,10 +20,10 @@ import androidx.appcompat.widget.LinearLayoutCompat
1920
import androidx.navigation.NavOptions
2021
import com.github.droidworksstudio.common.showLongToast
2122
import com.github.droidworksstudio.launcher.BuildConfig
22-
import com.github.droidworksstudio.launcher.utils.Constants
2323
import com.github.droidworksstudio.launcher.R
2424
import com.github.droidworksstudio.launcher.accessibility.ActionService
2525
import com.github.droidworksstudio.launcher.helper.weather.WeatherResponse
26+
import com.github.droidworksstudio.launcher.utils.Constants
2627
import com.github.droidworksstudio.launcher.utils.WeatherApiService
2728
import com.google.gson.Gson
2829
import retrofit2.Retrofit
@@ -115,6 +116,7 @@ class AppHelper @Inject constructor() {
115116
// Digital Wellbeing app is not installed or cannot be opened
116117
// Handle this case as needed
117118
context.showLongToast("Digital Wellbeing is not available on this device.")
119+
Log.e("AppHelper", "Digital Wellbeing app not found or cannot be opened.", e)
118120
}
119121
}
120122

@@ -170,27 +172,34 @@ class AppHelper @Inject constructor() {
170172
return dailyWordsArray[wordIndex]
171173
}
172174

173-
fun shareAppButton(context: Context) {
175+
fun shareApplicationButton(context: Context) {
174176
val shareIntent = Intent(Intent.ACTION_SEND)
177+
val description = context.getString(R.string.advanced_settings_share_application_description, context.getString(R.string.app_name))
175178
shareIntent.type = "text/plain"
176179
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Share Application")
177180
shareIntent.putExtra(
178181
Intent.EXTRA_TEXT,
179-
"https://f-droid.org/packages/" + context.packageName
182+
"$description https://f-droid.org/packages/${context.packageName}"
180183
)
181184
context.startActivity(Intent.createChooser(shareIntent, "Share Application"))
182185
}
183186

184-
fun githubButton(context: Context) {
187+
fun helpFeedbackButton(context: Context) {
185188
val uri = Uri.parse("https://github.com/DroidWorksStudio/EasyLauncher")
186189
val intent = Intent(Intent.ACTION_VIEW, uri)
187190
context.startActivity(intent)
188191
}
189192

190-
fun feedbackButton(context: Context) {
193+
fun communitySupportButton(context: Context) {
194+
val uri = Uri.parse("https://t.me/DroidWorksStudio/")
195+
val intent = Intent(Intent.ACTION_VIEW, uri)
196+
context.startActivity(intent)
197+
}
198+
199+
fun emailButton(context: Context) {
191200
val emailIntent = Intent(Intent.ACTION_SENDTO)
192201
emailIntent.data = Uri.parse("mailto:[email protected]")
193-
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Easy Launcher")
202+
emailIntent.putExtra(Intent.EXTRA_SUBJECT, R.string.app_name)
194203
context.startActivity(Intent.createChooser(emailIntent, "Choose Mail Application"))
195204
}
196205

@@ -307,6 +316,7 @@ class AppHelper @Inject constructor() {
307316
return WeatherResult.Failure("Failed to fetch weather data: ${response.errorBody()}")
308317
}
309318
} catch (e: UnknownHostException) {
319+
Log.e("AppHelper", "Unknown Host.", e)
310320
return WeatherResult.Failure("Unknown Host : $baseURL")
311321
} catch (e: Exception) {
312322
return WeatherResult.Failure("${e.message}")

app/src/main/java/com/github/droidworksstudio/launcher/ui/activities/MainActivity.kt

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package com.github.droidworksstudio.launcher.ui.activities
22

33
import android.Manifest
44
import android.annotation.SuppressLint
5-
import android.app.Activity
6-
import android.content.Context
75
import android.content.Intent
86
import android.content.SharedPreferences
97
import android.content.pm.ActivityInfo
@@ -24,6 +22,7 @@ import androidx.annotation.RequiresApi
2422
import androidx.appcompat.app.AppCompatActivity
2523
import androidx.core.app.ActivityCompat
2624
import androidx.core.content.ContextCompat
25+
import androidx.fragment.app.FragmentManager
2726
import androidx.lifecycle.lifecycleScope
2827
import androidx.navigation.NavController
2928
import androidx.navigation.findNavController
@@ -33,6 +32,7 @@ import androidx.navigation.ui.navigateUp
3332
import com.github.droidworksstudio.common.hasInternetPermission
3433
import com.github.droidworksstudio.common.isTablet
3534
import com.github.droidworksstudio.common.showLongToast
35+
import com.github.droidworksstudio.common.showShortToast
3636
import com.github.droidworksstudio.launcher.R
3737
import com.github.droidworksstudio.launcher.databinding.ActivityMainBinding
3838
import com.github.droidworksstudio.launcher.helper.AppHelper
@@ -89,7 +89,7 @@ class MainActivity : AppCompatActivity() {
8989
setContentView(binding.root)
9090

9191
locationManager = getSystemService(LOCATION_SERVICE) as LocationManager
92-
sharedPreferences = getSharedPreferences(Constants.WEATHER_PREFS, Context.MODE_PRIVATE)
92+
sharedPreferences = getSharedPreferences(Constants.WEATHER_PREFS, MODE_PRIVATE)
9393
handler = Handler(Looper.getMainLooper())
9494

9595
initializeDependencies()
@@ -218,7 +218,7 @@ class MainActivity : AppCompatActivity() {
218218

219219
onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) {
220220
override fun handleOnBackPressed() {
221-
backToHomeScreen()
221+
goBackToSettings()
222222
}
223223
})
224224
}
@@ -268,8 +268,29 @@ class MainActivity : AppCompatActivity() {
268268

269269
private fun backToHomeScreen() {
270270
navController = findNavController(R.id.nav_host_fragment_content_main)
271-
if (navController.currentDestination?.id != R.id.HomeFragment)
272-
navController.navigate(R.id.HomeFragment)
271+
when (navController.currentDestination?.id) {
272+
R.id.HomeFragment -> return
273+
else -> navController.navigate(R.id.HomeFragment)
274+
}
275+
}
276+
277+
private fun goBackToSettings() {
278+
navController = findNavController(R.id.nav_host_fragment_content_main)
279+
val fragmentManager: FragmentManager = supportFragmentManager
280+
when (navController.currentDestination?.id) {
281+
R.id.SettingsFragment,
282+
R.id.SettingsFeaturesFragment,
283+
R.id.SettingsLookFeelFragment,
284+
R.id.FavoriteFragment,
285+
R.id.HiddenFragment,
286+
R.id.SettingsAdvancedFragment -> {
287+
fragmentManager.popBackStack()
288+
}
289+
290+
else -> {
291+
navController.navigate(R.id.HomeFragment)
292+
}
293+
}
273294
}
274295

275296

@@ -296,7 +317,7 @@ class MainActivity : AppCompatActivity() {
296317
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
297318
super.onActivityResult(requestCode, resultCode, data)
298319

299-
if (resultCode != Activity.RESULT_OK) {
320+
if (resultCode != RESULT_OK) {
300321
applicationContext.showLongToast("Intent Error")
301322
return
302323
}
@@ -320,6 +341,7 @@ class MainActivity : AppCompatActivity() {
320341
prefs.loadFromString(string)
321342
}
322343
}
344+
applicationContext.showShortToast(getString(R.string.settings_reload_app_restore))
323345
Handler(Looper.getMainLooper()).postDelayed({
324346
AppReloader.restartApp(applicationContext)
325347
}, 500)
@@ -335,6 +357,7 @@ class MainActivity : AppCompatActivity() {
335357
}
336358
}
337359
}
360+
applicationContext.showShortToast(getString(R.string.settings_reload_app_backup))
338361
}
339362
}
340363
}

0 commit comments

Comments
 (0)