Added restart service option in settings

This commit is contained in:
Electric1447
2021-08-25 01:30:07 +03:00
parent e2ff79aced
commit 54356616ee
8 changed files with 52 additions and 40 deletions
+1 -1
View File
@@ -57,7 +57,7 @@
android:theme="@style/AppTheme.NoActionBar" />
<receiver
android:name=".receivers.Starter"
android:name=".receivers.StartupReceiver"
android:enabled="true"
android:exported="true"
android:label="@string/app_name">
@@ -50,11 +50,13 @@ public class NotificationBuilder {
notification.setImageViewResource(R.id.leftPodImg, status.getLeftPod().isConnected() ? R.drawable.pod : R.drawable.pod_disconnected);
notification.setImageViewResource(R.id.rightPodImg, status.getRightPod().isConnected() ? R.drawable.pod : R.drawable.pod_disconnected);
notification.setImageViewResource(R.id.podCaseImg, status.getCasePod().isConnected() ? R.drawable.pod_case : R.drawable.pod_case_disconnected);
} else if (status.isAirpodsPro()) for (RemoteViews notification : notificationArr) {
}
else if (status.isAirpodsPro()) for (RemoteViews notification : notificationArr) {
notification.setImageViewResource(R.id.leftPodImg, status.getLeftPod().isConnected() ? R.drawable.podpro : R.drawable.podpro_disconnected);
notification.setImageViewResource(R.id.rightPodImg, status.getRightPod().isConnected() ? R.drawable.podpro : R.drawable.podpro_disconnected);
notification.setImageViewResource(R.id.podCaseImg, status.getCasePod().isConnected() ? R.drawable.podpro_case : R.drawable.podpro_case_disconnected);
} else if (status.isAirpodsMax()) for (RemoteViews notification : notificationArr) {
}
else if (status.isAirpodsMax()) for (RemoteViews notification : notificationArr) {
notification.setImageViewResource(R.id.leftPodImg, status.getMaxPod().isConnected() ? R.drawable.podmax : R.drawable.podmax_disconnected);
}
@@ -83,7 +85,7 @@ public class NotificationBuilder {
notification.setViewVisibility(R.id.rightBatImg, batImgVisibility(status.getRightPod()));
notification.setViewVisibility(R.id.caseBatImg, batImgVisibility(status.getCasePod()));
notification.setViewVisibility(R.id.leftInEarImg, status.getLeftPod().isInEar()? View.VISIBLE : View.INVISIBLE);
notification.setViewVisibility(R.id.leftInEarImg, status.getLeftPod().isInEar() ? View.VISIBLE : View.INVISIBLE);
notification.setViewVisibility(R.id.rightInEarImg, status.getRightPod().isInEar() ? View.VISIBLE : View.INVISIBLE);
}
else for (RemoteViews notification : notificationArr) {
@@ -10,9 +10,9 @@ import com.dosse.airpods.pods.PodsService;
import java.util.Objects;
/**
* A simple starter class that starts the service when the device is booted, or after an update
* A simple startup class that starts the service when the device is booted, or after an update
*/
public class Starter extends BroadcastReceiver {
public class StartupReceiver extends BroadcastReceiver {
@Override
public void onReceive (Context context, Intent intent) {
@@ -15,7 +15,7 @@ import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import com.dosse.airpods.R;
import com.dosse.airpods.receivers.Starter;
import com.dosse.airpods.receivers.StartupReceiver;
import com.dosse.airpods.utils.PermissionUtils;
import java.util.Objects;
@@ -36,7 +36,7 @@ public class MainActivity extends AppCompatActivity {
}
if (PermissionUtils.checkAllPermissions(this)) {
Starter.startPodsService(getApplicationContext());
StartupReceiver.startPodsService(getApplicationContext());
//Warn MIUI users that their rom has known issues
try {
@SuppressLint("PrivateApi") Class<?> c = Class.forName("android.os.SystemProperties");
@@ -9,7 +9,7 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.preference.PreferenceManager;
import com.dosse.airpods.R;
import com.dosse.airpods.receivers.Starter;
import com.dosse.airpods.receivers.StartupReceiver;
import java.util.Objects;
@@ -32,7 +32,7 @@ public class SettingsActivity extends AppCompatActivity implements SharedPrefere
@Override
public void onSharedPreferenceChanged (SharedPreferences sharedPreferences, String key) {
if (key.equalsIgnoreCase("batterySaver"))
Starter.restartPodsService(getApplicationContext());
StartupReceiver.restartPodsService(getApplicationContext());
}
@Override
@@ -19,33 +19,39 @@ import static com.dosse.airpods.ui.AboutActivity.websiteURL;
import com.dosse.airpods.BuildConfig;
import com.dosse.airpods.R;
import com.dosse.airpods.receivers.StartupReceiver;
import com.dosse.airpods.utils.Logger;
import java.util.Objects;
public class SettingsFragment extends PreferenceFragmentCompat {
private Context context;
@SuppressWarnings("FieldCanBeLocal")
private Preference mAboutPreference, mHideAppPreference, mFDroidPreference, mWebsitePreference, mGithubPreference, mDonationPreference;
private Preference mHideAppPreference;
@Override
public void onCreatePreferences (Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.preference_screen, rootKey);
context = getContext();
Preference mRestartPreference = getPreferenceManager().findPreference("restartService");
Objects.requireNonNull(mRestartPreference).setOnPreferenceClickListener(preference -> {
StartupReceiver.restartPodsService(requireContext());
return true;
});
mHideAppPreference = getPreferenceManager().findPreference("hideApp");
assert mHideAppPreference != null;
mHideAppPreference.setOnPreferenceClickListener(preference -> {
Objects.requireNonNull(mHideAppPreference).setOnPreferenceClickListener(preference -> {
AlertDialog.Builder builder = new AlertDialog.Builder(requireContext());
builder.setTitle(R.string.hide_dialog);
builder.setMessage(R.string.hide_dialog_desc);
builder.setPositiveButton(R.string.hide_dialog_button, (dialog, which) -> {
PackageManager p = requireContext().getPackageManager();
p.setComponentEnabledSetting(new ComponentName(context, MainActivity.class), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
Toast.makeText(context, getString(R.string.hideClicked), Toast.LENGTH_LONG).show();
p.setComponentEnabledSetting(new ComponentName(requireContext(), MainActivity.class), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
Toast.makeText(requireContext(), getString(R.string.hideClicked), Toast.LENGTH_LONG).show();
try {
context.openFileOutput("hidden", Context.MODE_PRIVATE).close();
} catch (Throwable ignored) {
requireContext().openFileOutput("hidden", Context.MODE_PRIVATE).close();
} catch (Throwable t) {
Logger.error(t);
}
enableDisableOptions();
@@ -56,40 +62,35 @@ public class SettingsFragment extends PreferenceFragmentCompat {
return true;
});
mAboutPreference = getPreferenceManager().findPreference("about");
assert mAboutPreference != null;
mAboutPreference.setSummary(String.format("%s v%s", getString(R.string.app_name), BuildConfig.VERSION_NAME));
Preference mAboutPreference = getPreferenceManager().findPreference("about");
Objects.requireNonNull(mAboutPreference).setSummary(String.format("%s v%s", getString(R.string.app_name), BuildConfig.VERSION_NAME));
mAboutPreference.setOnPreferenceClickListener(preference -> {
startActivity(new Intent(context, AboutActivity.class));
startActivity(new Intent(requireContext(), AboutActivity.class));
return true;
});
mFDroidPreference = getPreferenceManager().findPreference("fdroid");
assert mFDroidPreference != null;
mFDroidPreference.setOnPreferenceClickListener(preference -> {
Preference mFDroidPreference = getPreferenceManager().findPreference("fdroid");
Objects.requireNonNull(mFDroidPreference).setOnPreferenceClickListener(preference -> {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(fdroidURL)));
return true;
});
mGithubPreference = getPreferenceManager().findPreference("github");
assert mGithubPreference != null;
mGithubPreference.setOnPreferenceClickListener(preference -> {
Preference mGithubPreference = getPreferenceManager().findPreference("github");
Objects.requireNonNull(mGithubPreference).setOnPreferenceClickListener(preference -> {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(githubURL)));
return true;
});
mWebsitePreference = getPreferenceManager().findPreference("website");
assert mWebsitePreference != null;
mWebsitePreference.setOnPreferenceClickListener(preference -> {
Preference mWebsitePreference = getPreferenceManager().findPreference("website");
Objects.requireNonNull(mWebsitePreference).setOnPreferenceClickListener(preference -> {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(websiteURL)));
return true;
});
mDonationPreference = getPreferenceManager().findPreference("donate");
assert mDonationPreference != null;
mDonationPreference.setOnPreferenceClickListener(preference -> {
Preference mDonationPreference = getPreferenceManager().findPreference("donate");
Objects.requireNonNull(mDonationPreference).setOnPreferenceClickListener(preference -> {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(donateURL)));
Toast.makeText(getContext(), "❤️", Toast.LENGTH_SHORT).show();
Toast.makeText(requireContext(), "❤️", Toast.LENGTH_SHORT).show();
return true;
});
@@ -98,9 +99,10 @@ public class SettingsFragment extends PreferenceFragmentCompat {
private void enableDisableOptions () {
try {
context.openFileInput("hidden").close();
requireContext().openFileInput("hidden").close();
mHideAppPreference.setEnabled(false);
} catch (Throwable ignored) {
} catch (Throwable t) {
Logger.error(t);
}
}
@@ -33,6 +33,8 @@
<string name="batterySaver">Battery saver (Not recommended)</string>
<string name="batterySaver_desc">Enable this if Bluetooth uses a lot of battery</string>
<string name="restart" tools:ignore="MissingTranslation">Restart Service</string>
<string name="restart_desc" tools:ignore="MissingTranslation">Do this if the notification is not showing</string>
<string name="hide">Hide app</string>
<string name="hide_desc">Hide this app from the launcher</string>
<string name="hide_dialog" tools:ignore="MissingTranslation">Are you sure?</string>
@@ -13,6 +13,12 @@
android:title="@string/batterySaver"
app:iconSpaceReserved="false" />
<Preference
android:key="restartService"
android:summary="@string/restart_desc"
android:title="@string/restart"
app:iconSpaceReserved="false" />
<Preference
android:key="hideApp"
android:summary="@string/hide_desc"