Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 39d6f319 authored by Amit Kumar's avatar Amit Kumar
Browse files

Add oreo and nougat flavours for maintaining different source for various parts

parent 7b0d96d7
Loading
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -28,7 +28,17 @@ android {
            keyAlias 'androiddebugkey'
            keyPassword 'android'
        }
    }

    flavorDimensions "api"
    productFlavors {
        apiNougat {
            dimension "api"
        }
        apiOreo {
            dimension "api"
            minSdkVersion 26
        }
    }

    // Always show the result of every unit test, even if it passes.
@@ -47,10 +57,12 @@ dependencies {
    implementation 'me.relex:circleindicator:1.2.2@aar'
    implementation 'uk.co.chrisjenx:calligraphy:2.3.0'

    implementation files('libs/lineage-sdk.jar')
    apiNougatImplementation 'org.cyanogenmod:platform.sdk:6.0'
    apiOreoImplementation files('libs/lineage-sdk.jar')

    debugImplementation 'com.crashlytics.sdk.android:crashlytics:2.9.5'
    debugImplementation 'com.google.firebase:firebase-core:16.0.4'

    implementation 'org.greenrobot:eventbus:3.1.1'

    // Support Libs
+6 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="org.indin.blisslaunchero">
    <uses-permission android:name="cyanogenmod.permission.ACCESS_WEATHER_MANAGER"/>
    <uses-permission android:name="cyanogenmod.permission.READ_WEATHER"/>
</manifest>
 No newline at end of file
+2603 −0

File added.

Preview size limit exceeded, changes collapsed.

+163 −0
Original line number Diff line number Diff line
package org.indin.blisslaunchero.features.weather;

import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Handler;
import android.preference.EditTextPreference;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import org.indin.blisslaunchero.R;
import org.indin.blisslaunchero.framework.Preferences;

import java.util.HashSet;
import java.util.List;

import cyanogenmod.weather.CMWeatherManager;
import cyanogenmod.weather.WeatherLocation;

public class CustomLocationPreference extends EditTextPreference
        implements CMWeatherManager.LookupCityRequestListener {
    public CustomLocationPreference(Context context) {
        super(context);
    }

    public CustomLocationPreference(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomLocationPreference(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    private ProgressDialog mProgressDialog;
    private int mCustomLocationRequestId;
    private Handler mHandler;

    @Override
    protected void showDialog(Bundle state) {
        super.showDialog(state);
        mHandler = new Handler(getContext().getMainLooper());

        final AlertDialog d = (AlertDialog) getDialog();
        final Button okButton = d.getButton(DialogInterface.BUTTON_POSITIVE);
        okButton.setOnClickListener(v -> {
            CustomLocationPreference.this.onClick(d, DialogInterface.BUTTON_POSITIVE);
            final String customLocationToLookUp = getEditText().getText().toString();
            if (TextUtils.equals(customLocationToLookUp, "")) return;
            final CMWeatherManager weatherManager = CMWeatherManager.getInstance(getContext());
            mProgressDialog = new ProgressDialog(getContext());
            mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
            mProgressDialog.setMessage(getContext().getString(R.string.weather_progress_title));
            mProgressDialog.setOnCancelListener(
                    dialog -> weatherManager.cancelRequest(mCustomLocationRequestId));
            mCustomLocationRequestId = weatherManager.lookupCity(customLocationToLookUp,
                    CustomLocationPreference.this);
            mProgressDialog.show();
        });
    }

    @Override
    protected void onBindDialogView(View view) {
        super.onBindDialogView(view);

        String location = Preferences.getCustomWeatherLocationCity(getContext());
        if (location != null) {
            getEditText().setText(location);
            getEditText().setSelection(location.length());
        } else {
            getEditText().setText("");
        }
    }

    @Override
    protected void onDialogClosed(boolean positiveResult) {
        // we handle persisting the selected location below, so pretend cancel
        super.onDialogClosed(false);
    }

    private void handleResultDisambiguation(final List<WeatherLocation> results) {
        CharSequence[] items = buildItemList(results);
        new AlertDialog.Builder(getContext())
                .setSingleChoiceItems(items, -1, (dialog, which) -> {
                    applyLocation(results.get(which));
                    dialog.dismiss();
                })
                .setNegativeButton(android.R.string.cancel, null)
                .setTitle(R.string.weather_select_location)
                .show();
    }

    private CharSequence[] buildItemList(List<WeatherLocation> results) {
        boolean needCountry = false, needPostal = false;
        String countryId = results.get(0).getCountryId();
        HashSet<String> postalIds = new HashSet<>();

        for (WeatherLocation result : results) {
            if (!TextUtils.equals(result.getCountryId(), countryId)) {
                needCountry = true;
            }
            String postalId = result.getCountryId() + "##" + result.getCity();
            if (postalIds.contains(postalId)) {
                needPostal = true;
            }
            postalIds.add(postalId);
            if (needPostal && needCountry) {
                break;
            }
        }

        int count = results.size();
        CharSequence[] items = new CharSequence[count];
        for (int i = 0; i < count; i++) {
            WeatherLocation result = results.get(i);
            StringBuilder builder = new StringBuilder();
            if (needPostal && result.getPostalCode() != null) {
                builder.append(result.getPostalCode()).append(" ");
            }
            builder.append(result.getCity());
            if (needCountry) {
                String country = result.getCountry() != null
                        ? result.getCountry() : result.getCountryId();
                builder.append(" (").append(country).append(")");
            }
            items[i] = builder.toString();
        }
        return items;
    }

    private void applyLocation(final WeatherLocation result) {
        if (Preferences.setCustomWeatherLocation(getContext(), result)) {
            String cityName = result.getCity();
            String state = result.getState();
            String country = result.getCountry();
            setText(cityName + "," + state + "/" + country);
        }
        final AlertDialog d = (AlertDialog) getDialog();
        d.dismiss();
    }

    @Override
    public void onLookupCityRequestCompleted(int status, final List<WeatherLocation> locations) {
        mHandler.post(() -> {
            final Context context = getContext();
            if (locations == null || locations.isEmpty()) {
                Toast.makeText(context,
                        context.getString(R.string.weather_retrieve_location_dialog_title),
                        Toast.LENGTH_SHORT)
                        .show();
            } else if (locations.size() > 1) {
                handleResultDisambiguation(locations);
            } else {
                applyLocation(locations.get(0));
            }
            mProgressDialog.dismiss();
        });
    }
}
+72 −0
Original line number Diff line number Diff line
package org.indin.blisslaunchero.features.weather;

import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.os.IBinder;
import android.util.Log;

import org.indin.blisslaunchero.framework.utils.Constants;

public class DeviceStatusService extends Service {

    private static final String TAG = DeviceStatusService.class.getSimpleName();
    private static final boolean D = Constants.DEBUG;

    private BroadcastReceiver mDeviceStatusListenerReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();

            // Network connection has changed, make sure the weather update service knows about it
            if (ConnectivityManager.CONNECTIVITY_ACTION.equals(action)) {
                boolean hasConnection = !intent.getBooleanExtra(
                        ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);

                if (D) Log.d(TAG, "Got connectivity change, has connection: " + hasConnection);

                Intent i = new Intent(context, WeatherUpdateService.class);
                if (hasConnection) {
                    context.startService(i);
                } else {
                    context.stopService(i);
                }
            } else if (Intent.ACTION_SCREEN_OFF.equals(action)) {
                if (D) Log.d(TAG, "onDisplayOff: Cancel pending update");
                WeatherUpdateService.cancelUpdates(context);
            } else if (Intent.ACTION_SCREEN_ON.equals(action)) {
                if (D) Log.d(TAG, "onDisplayOn: Reschedule update");
                WeatherUpdateService.scheduleNextUpdate(context, false);
            }
        }
    };

    @Override
    public void onCreate() {
        IntentFilter deviceStatusFilter = new IntentFilter();
        deviceStatusFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
        deviceStatusFilter.addAction(Intent.ACTION_SCREEN_OFF);
        deviceStatusFilter.addAction(Intent.ACTION_SCREEN_ON);
        registerReceiver(mDeviceStatusListenerReceiver, deviceStatusFilter);
    }

    @Override
    public void onDestroy() {
        if (D) Log.d(TAG, "Stopping service");
        unregisterReceiver(mDeviceStatusListenerReceiver);
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        if (D) Log.d(TAG, "Starting service");
        return START_STICKY;
    }

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }
}
Loading