2024-01-10 18:54:00 +01:00
|
|
|
/* Copyright (C) 2023-2024 José Rebelo
|
2023-07-04 00:19:19 +02:00
|
|
|
|
|
|
|
This file is part of Gadgetbridge.
|
|
|
|
|
|
|
|
Gadgetbridge is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as published
|
|
|
|
by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Gadgetbridge is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
2024-01-10 18:54:00 +01:00
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
2023-07-04 00:19:19 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.activities.loyaltycards;
|
|
|
|
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.view.MenuItem;
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.core.app.ActivityCompat;
|
|
|
|
import androidx.fragment.app.Fragment;
|
|
|
|
import androidx.fragment.app.FragmentManager;
|
|
|
|
import androidx.preference.PreferenceFragmentCompat;
|
|
|
|
import androidx.preference.PreferenceScreen;
|
|
|
|
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractGBActivity;
|
2023-07-28 23:47:39 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractSettingsActivityV2;
|
2023-07-04 00:19:19 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
|
|
|
|
|
|
|
|
2023-07-28 23:47:39 +02:00
|
|
|
public class LoyaltyCardsSettingsActivity extends AbstractSettingsActivityV2 implements
|
2023-07-04 00:19:19 +02:00
|
|
|
PreferenceFragmentCompat.OnPreferenceStartScreenCallback,
|
|
|
|
ActivityCompat.OnRequestPermissionsResultCallback {
|
|
|
|
|
|
|
|
public static final int PERMISSION_REQUEST_CODE = 0;
|
|
|
|
|
|
|
|
private GBDevice device;
|
|
|
|
|
|
|
|
@Override
|
2023-07-28 23:47:39 +02:00
|
|
|
protected String fragmentTag() {
|
|
|
|
return LoyaltyCardsSettingsFragment.FRAGMENT_TAG;
|
2023-07-04 00:19:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-07-28 23:47:39 +02:00
|
|
|
protected PreferenceFragmentCompat newFragment() {
|
|
|
|
return LoyaltyCardsSettingsFragment.newInstance(device);
|
2023-07-04 00:19:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-07-28 23:47:39 +02:00
|
|
|
protected void onCreate(final Bundle savedInstanceState) {
|
|
|
|
device = getIntent().getParcelableExtra(GBDevice.EXTRA_DEVICE);
|
2023-07-04 00:19:19 +02:00
|
|
|
|
2023-07-28 23:47:39 +02:00
|
|
|
super.onCreate(savedInstanceState);
|
2023-07-04 00:19:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRequestPermissionsResult(final int requestCode,
|
|
|
|
@NonNull final String[] permissions,
|
|
|
|
@NonNull final int[] grantResults) {
|
|
|
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
|
|
|
|
|
|
|
if (requestCode != PERMISSION_REQUEST_CODE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (grantResults.length == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
|
|
|
final FragmentManager fragmentManager = getSupportFragmentManager();
|
|
|
|
final Fragment fragment = fragmentManager.findFragmentByTag(LoyaltyCardsSettingsFragment.FRAGMENT_TAG);
|
|
|
|
if (fragment == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fragment instanceof LoyaltyCardsSettingsFragment) {
|
|
|
|
((LoyaltyCardsSettingsFragment) fragment).reloadPreferences(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|