-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6b3b1ac
commit 96174cf
Showing
81 changed files
with
2,270 additions
and
1,817 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
.gradle | ||
.idea | ||
build/ | ||
app/build/ | ||
app/release/ | ||
local.properties | ||
gradle.properties | ||
.gradle/ | ||
.idea/ | ||
.stignore | ||
.stfolder/ | ||
build/ | ||
app/build/ | ||
app/release/ | ||
local.properties | ||
gradle.properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
package com.truemlgpro.wifiinfo; | ||
|
||
import android.app.Activity; | ||
import android.app.Application; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.content.SharedPreferences; | ||
import android.os.Build; | ||
import android.os.Bundle; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import androidx.preference.PreferenceManager; | ||
|
||
import com.truemlgpro.wifiinfo.interfaces.PreferenceDefaults; | ||
import com.truemlgpro.wifiinfo.interfaces.PreferenceKeys; | ||
import com.truemlgpro.wifiinfo.services.ConnectionStateService; | ||
import com.truemlgpro.wifiinfo.services.NotificationService; | ||
import com.truemlgpro.wifiinfo.ui.SettingsActivity; | ||
|
||
public class App extends Application { | ||
private SharedPreferences.OnSharedPreferenceChangeListener sharedPrefChangeListener; | ||
Intent connectionStateServiceIntent; | ||
Intent notificationServiceIntent; | ||
|
||
@Override | ||
public void onCreate() { | ||
super.onCreate(); | ||
registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() { | ||
@Override | ||
public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) { | ||
// Stub | ||
} | ||
|
||
@Override | ||
public void onActivityStarted(Activity activity) { | ||
// Stub | ||
} | ||
|
||
@Override | ||
public void onActivityResumed(Activity activity) { | ||
if (activity.getClass().equals(SettingsActivity.class)) | ||
initSharedPrefs(activity); | ||
} | ||
|
||
@Override | ||
public void onActivityPaused(Activity activity) { | ||
if (activity.getClass().equals(SettingsActivity.class)) { | ||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); | ||
prefs.unregisterOnSharedPreferenceChangeListener(sharedPrefChangeListener); | ||
} | ||
} | ||
|
||
@Override | ||
public void onActivityStopped(Activity activity) { | ||
// Stub | ||
} | ||
|
||
@Override | ||
public void onActivitySaveInstanceState(Activity activity, Bundle bundle) { | ||
// Stub | ||
} | ||
|
||
@Override | ||
public void onActivityDestroyed(Activity activity) { | ||
// Stub | ||
} | ||
}); | ||
} | ||
|
||
private void initSharedPrefs(Activity activity) { | ||
connectionStateServiceIntent = new Intent(this, ConnectionStateService.class); | ||
notificationServiceIntent = new Intent(this, NotificationService.class); | ||
sharedPrefChangeListener = (prefs, key) -> { | ||
switch (key) { | ||
case PreferenceKeys.KEY_PREF_DARK_MODE, | ||
PreferenceKeys.KEY_PREF_AMOLED_MODE, | ||
PreferenceKeys.KEY_PREF_APP_FONT, | ||
PreferenceKeys.KEY_PREF_KEEP_SCREEN_ON -> | ||
restartSettingsActivity(activity); | ||
case PreferenceKeys.KEY_PREF_APP_LANGUAGE -> { | ||
restartSettingsActivity(activity); | ||
if (prefs.getBoolean(PreferenceKeys.KEY_PREF_SHOW_NTFC, PreferenceDefaults.SHOW_NTFC)) | ||
restartServices(this); | ||
} | ||
case PreferenceKeys.KEY_PREF_SHOW_NTFC -> { | ||
if (prefs.getBoolean(PreferenceKeys.KEY_PREF_SHOW_NTFC, PreferenceDefaults.SHOW_NTFC)) { | ||
startServices(this); | ||
} else { | ||
stopServices(this); | ||
} | ||
} | ||
case PreferenceKeys.KEY_PREF_START_STOP_SVC -> restartServices(this); | ||
} | ||
}; | ||
|
||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); | ||
prefs.registerOnSharedPreferenceChangeListener(sharedPrefChangeListener); | ||
} | ||
|
||
private void startServices(Context context) { | ||
if (!ConnectionStateService.isConnectionStateServiceRunning) { | ||
if (Build.VERSION.SDK_INT < 26) { | ||
context.startService(connectionStateServiceIntent); | ||
} else { | ||
context.startForegroundService(connectionStateServiceIntent); | ||
} | ||
} | ||
} | ||
|
||
private void stopServices(Context context) { | ||
context.stopService(notificationServiceIntent); | ||
context.stopService(connectionStateServiceIntent); | ||
} | ||
|
||
private void restartServices(Context context) { | ||
context.stopService(notificationServiceIntent); | ||
context.stopService(connectionStateServiceIntent); | ||
if (Build.VERSION.SDK_INT < 26) { | ||
context.startService(connectionStateServiceIntent); | ||
} else { | ||
context.startForegroundService(connectionStateServiceIntent); | ||
} | ||
} | ||
|
||
private void restartSettingsActivity(Activity activity) { | ||
if (activity.getClass().equals(SettingsActivity.class)) { | ||
Intent activityRestartIntent = new Intent(this, SettingsActivity.class); | ||
activity.finish(); | ||
activity.overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); | ||
activity.startActivity(activityRestartIntent); | ||
activity.overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.