Java Code Examples for com.gianlu.commonutils.preferences.Prefs#getBoolean()

The following examples show how to use com.gianlu.commonutils.preferences.Prefs#getBoolean() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FilesFragment.java    From Aria2App with GNU General Public License v3.0 6 votes vote down vote up
private void shouldDownload(@NonNull MultiProfile profile, @NonNull OptionsMap global, @NonNull AriaFile file, boolean share) {
    AnalyticsApplication.sendAnalytics(Utils.ACTION_DOWNLOAD_FILE);

    if (Prefs.getBoolean(PK.DD_USE_EXTERNAL) || share) {
        MultiProfile.DirectDownload dd = profile.getProfile(getContext()).directDownload;
        HttpUrl base;
        if (dd == null || (base = dd.getUrl()) == null) return;

        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse(file.getDownloadUrl(global, base).toString()));

        if (dd.auth) {
            Bundle headers = new Bundle();
            headers.putString("Authorization", dd.getAuthorizationHeader());
            intent.putExtra(Browser.EXTRA_HEADERS, headers);
        }

        startActivity(intent);
    } else {
        startDownloadInternal(profile, file, null);
    }
}
 
Example 2
Source File: FilesFragment.java    From Aria2App with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onDownloadDirectory(@NonNull MultiProfile profile, @NonNull AriaDirectory dir) {
    if (dirSheet != null) {
        dirSheet.dismiss();
        dirSheet = null;
        dismissDialog();
    }

    AnalyticsApplication.sendAnalytics(Utils.ACTION_DOWNLOAD_DIRECTORY);

    if (Prefs.getBoolean(PK.DD_USE_EXTERNAL)) {
        AlertDialog.Builder builder = new MaterialAlertDialogBuilder(requireContext());
        builder.setTitle(R.string.cannotDownloadDirWithExternal)
                .setMessage(R.string.cannotDownloadDirWithExternal_message)
                .setPositiveButton(android.R.string.yes, (dialog, which) -> startDownloadInternal(profile, null, dir))
                .setNegativeButton(android.R.string.no, null);

        showDialog(builder);
    } else {
        startDownloadInternal(profile, null, dir);
    }
}
 
Example 3
Source File: AnalyticsApplication.java    From CommonUtils with Apache License 2.0 5 votes vote down vote up
@Override
@CallSuper
public void onCreate() {
    super.onCreate();

    String uuid = Prefs.getString(CommonPK.ANALYTICS_USER_ID, null);
    if (uuid == null) {
        uuid = UUID.randomUUID().toString();
        Prefs.putString(CommonPK.ANALYTICS_USER_ID, uuid);
    }

    if (FossUtils.hasFirebaseCrashlytics()) {
        if (Prefs.getBoolean(CommonPK.CRASH_REPORT_ENABLED)) {
            FirebaseCrashlytics.getInstance().setUserId(uuid);
            CRASHLYTICS_ENABLED = true;
        } else {
            CRASHLYTICS_ENABLED = false;
        }
    } else {
        Prefs.putBoolean(CommonPK.CRASH_REPORT_ENABLED, false);
    }

    if (FossUtils.hasFirebaseAnalytics()) {
        ANALYTICS = FirebaseAnalytics.getInstance(this);
        if (Prefs.getBoolean(CommonPK.TRACKING_ENABLED)) {
            ANALYTICS.setUserId(uuid);
            ANALYTICS.setAnalyticsCollectionEnabled(true);
        } else {
            ANALYTICS.setAnalyticsCollectionEnabled(false);
            ANALYTICS = null;
        }
    } else {
        Prefs.putBoolean(CommonPK.TRACKING_ENABLED, false);
    }
}
 
Example 4
Source File: ThisApplication.java    From Aria2App with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void updateUi(boolean on) {
    if (!lastUiState && on && Prefs.getBoolean(PK.A2_ENABLE_NOTIFS))
        NotificationService.start(ThisApplication.this);

    lastUiState = on;

    for (Aria2Ui.Listener listener : new ArrayList<>(listeners))
        listener.updateUi(on);
}
 
Example 5
Source File: LoadingActivity.java    From Aria2App with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onConnected(@NonNull AbstractClient client) {
    ongoingTest = null;

    if (Prefs.getBoolean(PK.A2_ENABLE_NOTIFS, true))
        NotificationService.start(this);

    if (shareData != null) {
        try {
            new URL(shareData.toString());
        } catch (MalformedURLException ex) {
            launchMain();
            return false;
        }

        if (!Prefs.getBoolean(PK.A2_SKIP_WEBVIEW_DIALOG) && Utils.hasWebView(this)) {
            AlertDialog.Builder builder = new MaterialAlertDialogBuilder(this);
            builder.setTitle(R.string.useWebView)
                    .setMessage(R.string.useWebView_message)
                    .setPositiveButton(android.R.string.yes, (dialog, which) -> launchWebView())
                    .setNeutralButton(android.R.string.no, (dialog, which) -> launchMain());
            showDialog(builder);
            return false;
        }
    }

    launchMain();
    return false;
}
 
Example 6
Source File: BootCompletedReceiver.java    From Aria2App with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    if (Objects.equals(intent.getAction(), Intent.ACTION_BOOT_COMPLETED)) {
        if (Prefs.getBoolean(PK.A2_NOTIFS_AT_BOOT))
            NotificationService.start(context);

        if (Prefs.getBoolean(PK.IN_APP_DOWNLOADER_AT_BOOT))
            ((ThisApplication) context.getApplicationContext()).startAria2ServiceFromReceiver();
    }
}
 
Example 7
Source File: BootCompletedReceiver.java    From Aria2Android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    if (!Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction()))
        return;

    if (Prefs.getBoolean(PK.START_AT_BOOT))
        new Aria2Ui(context, null).startServiceFromReceiver();
}
 
Example 8
Source File: GamesFragment.java    From PretendYoureXyzzyAndroid with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onDone(@NonNull GamesList result) {
    if (!isAdded()) return;

    adapter = new GamesAdapter(getContext(), result, pyx, Prefs.getBoolean(PK.FILTER_LOCKED_LOBBIES), this);
    rmv.loadListData(adapter, false);

    lastResult = result;
    updateActivityTitle();
    if (launchGame != null) {
        launchGameInternal(launchGame, launchGamePassword, launchGameShouldRequest);
    } else {
        rmv.list().post(() -> tutorialManager.tryShowingTutorials(getActivity()));
    }
}
 
Example 9
Source File: LoadingActivity.java    From PretendYoureXyzzyAndroid with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_loading);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) actionBar.hide();

    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
            | View.SYSTEM_UI_FLAG_FULLSCREEN
            | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);

    new Handler().postDelayed(() -> {
        finished = true;
        if (goTo != null) startActivity(goTo);
    }, 1000);

    if (Prefs.getBoolean(PK.FIRST_RUN, true)) {
        startActivity(new Intent(this, TutorialActivity.class)
                .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK));
        return;
    }

    Button preferences = findViewById(R.id.loading_preferences);
    preferences.setOnClickListener(v -> startActivity(new Intent(LoadingActivity.this, PreferenceActivity.class)));

    tutorialManager = new TutorialManager(this, Discovery.LOGIN);

    loading = findViewById(R.id.loading_loading);
    loading.getIndeterminateDrawable().setColorFilter(CommonUtils.resolveAttrAsColor(this, android.R.attr.textColorPrimary), PorterDuff.Mode.SRC_IN);
    currentServer = findViewById(R.id.loading_currentServer);
    register = findViewById(R.id.loading_register);
    registerNickname = findViewById(R.id.loading_registerNickname);
    registerSubmit = findViewById(R.id.loading_registerSubmit);
    registerIdCode = findViewById(R.id.loading_registerIdCode);
    welcomeMessage = findViewById(R.id.loading_welcomeMsg);

    changeServer = findViewById(R.id.loading_changeServer);
    changeServer.setOnClickListener(v -> changeServerDialog(true));

    registerIdCode.setEndIconOnClickListener(v -> CommonUtils.setText(registerIdCode, CommonUtils.randomString(100, new SecureRandom())));
    CommonUtils.clearErrorOnEdit(registerIdCode);

    if (Objects.equals(getIntent().getAction(), Intent.ACTION_VIEW) || Objects.equals(getIntent().getAction(), Intent.ACTION_SEND)) {
        Uri url = getIntent().getData();
        if (url != null) {
            Pyx.Server server = Pyx.Server.fromUrl(url);
            if (server != null) setServer(server);

            String fragment = url.getFragment();
            if (fragment != null) {
                List<NameValuePair> params = Utils.splitQuery(fragment);
                for (NameValuePair pair : params) {
                    if (Objects.equals(pair.key(), "game")) {
                        try {
                            launchGame = new GamePermalink(Integer.parseInt(pair.value("")), new JSONObject()); // A bit hacky
                        } catch (NumberFormatException ignored) {
                        }
                    } else if (Objects.equals(pair.key(), "password")) {
                        launchGamePassword = pair.value("");
                    }
                }

                launchGameShouldRequest = true;
            }
        }
    }

    discoveryApi = PyxDiscoveryApi.get();
    discoveryApi.getWelcomeMessage(this, new Pyx.OnResult<String>() {
        @Override
        public void onDone(@NonNull String result) {
            if (result.isEmpty()) {
                welcomeMessage.setVisibility(View.GONE);
            } else {
                welcomeMessage.setVisibility(View.VISIBLE);
                welcomeMessage.setHtml(result);
            }
        }

        @Override
        public void onException(@NonNull Exception ex) {
            Log.e(TAG, "Failed loading welcome message.", ex);
            welcomeMessage.setVisibility(View.GONE);
        }
    });
    discoveryApi.firstLoad(this, null, this);

    signInSilently();
}