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

Commit df1b4ee0 authored by Yash Garg's avatar Yash Garg 💬
Browse files

Merge branch 'master-cleanup_unused' into 'master'

cleanup: remove unused :data, :domain modules and format all java files

See merge request !122
parents e82940d0 c8e890b3
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ android {
        testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
        renderscriptTargetApi = 28
        renderscriptSupportModeEnabled = true
        setProperty("archivesBaseName", "BlissLauncher-v$versionName")
        setProperty("archivesBaseName", "BlissLauncher-$versionName")
    }

    buildTypes {
+2 −3
Original line number Diff line number Diff line
@@ -17,12 +17,11 @@ package foundation.e.blisslauncher;

import static org.junit.Assert.*;

import org.junit.Test;
import org.junit.runner.RunWith;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
 * Instrumentation test, which will execute on an Android device.
+51 −58
Original line number Diff line number Diff line
@@ -3,24 +3,20 @@ package foundation.e.blisslauncher.core;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.Locale;

import cyanogenmod.weather.WeatherInfo;
import cyanogenmod.weather.WeatherLocation;
import foundation.e.blisslauncher.core.utils.Constants;
import java.util.ArrayList;
import java.util.Locale;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class Preferences {

    /**
     * Weather related keys and constants.
     */
    /** Weather related keys and constants. */
    private static final String WEATHER_LOCATION_CITY_ID = "city_id";

    private static final String WEATHER_LOCATION_CITY_NAME = "city_name";
    private static final String WEATHER_LOCATION_STATE = "state";
    private static final String WEATHER_LOCATION_POSTAL_CODE = "postal_code";
@@ -64,8 +60,8 @@ public class Preferences {
    }

    public static int weatherFontColor(Context context) {
        int color = Color.parseColor(getPrefs(context).getString(Constants.WEATHER_FONT_COLOR,
                Constants.DEFAULT_LIGHT_COLOR));
        int color = Color
                .parseColor(getPrefs(context).getString(Constants.WEATHER_FONT_COLOR, Constants.DEFAULT_LIGHT_COLOR));
        return color;
    }

@@ -75,8 +71,7 @@ public class Preferences {

    public static boolean useMetricUnits(Context context) {
        Locale locale = context.getResources().getConfiguration().locale;
        boolean defValue = !(locale.equals(Locale.US)
                || locale.toString().equals("ms_MY") // Malaysia
        boolean defValue = !(locale.equals(Locale.US) || locale.toString().equals("ms_MY") // Malaysia
                || locale.toString().equals("si_LK") // Sri Lanka
        );
        return getPrefs(context).getBoolean(Constants.WEATHER_USE_METRIC, defValue);
@@ -107,17 +102,14 @@ public class Preferences {
        getPrefs(context).edit().putString(Constants.WEATHER_CUSTOM_LOCATION_CITY, city).apply();
    }

    public static boolean setCustomWeatherLocation(Context context,
            WeatherLocation weatherLocation) {
    public static boolean setCustomWeatherLocation(Context context, WeatherLocation weatherLocation) {
        if (weatherLocation == null) {
            getPrefs(context).edit()
                    .remove(Constants.WEATHER_CUSTOM_LOCATION).apply();
            getPrefs(context).edit().remove(Constants.WEATHER_CUSTOM_LOCATION).apply();
            return true;
        }
        try {
            JSONObject jsonObject = weatherLocationToJSON(weatherLocation);
            getPrefs(context).edit()
                    .putString(Constants.WEATHER_CUSTOM_LOCATION, jsonObject.toString()).apply();
            getPrefs(context).edit().putString(Constants.WEATHER_CUSTOM_LOCATION, jsonObject.toString()).apply();
            return true;
        } catch (JSONException e) {
            // We're here because weatherLocationToJSON() or jsonObject.toString() failed.
@@ -127,8 +119,7 @@ public class Preferences {
    }

    public static WeatherLocation getCustomWeatherLocation(Context context) {
        String weatherLocation = getPrefs(context)
                .getString(Constants.WEATHER_CUSTOM_LOCATION, null);
        String weatherLocation = getPrefs(context).getString(Constants.WEATHER_CUSTOM_LOCATION, null);

        if (weatherLocation == null) {
            return null;
@@ -142,8 +133,7 @@ public class Preferences {
        }
    }

    private static WeatherLocation JSONToWeatherLocation(JSONObject jsonObject)
            throws JSONException {
    private static WeatherLocation JSONToWeatherLocation(JSONObject jsonObject) throws JSONException {
        String cityId;
        String cityName;
        String state;
@@ -164,19 +154,21 @@ public class Preferences {
        }

        WeatherLocation.Builder location = new WeatherLocation.Builder(cityId, cityName);
        if (countryId != null) location.setCountryId(countryId);
        if (countryName != null) location.setCountry(countryName);
        if (state != null) location.setState(state);
        if (postalCode != null) location.setPostalCode(postalCode);
        if (countryId != null)
            location.setCountryId(countryId);
        if (countryName != null)
            location.setCountry(countryName);
        if (state != null)
            location.setState(state);
        if (postalCode != null)
            location.setPostalCode(postalCode);

        return location.build();
    }

    private static JSONObject weatherLocationToJSON(WeatherLocation location) throws JSONException {
        return new JSONObject()
                .put(WEATHER_LOCATION_CITY_ID, location.getCityId())
                .put(WEATHER_LOCATION_CITY_NAME, location.getCity())
                .put(WEATHER_LOCATION_STATE, location.getState())
        return new JSONObject().put(WEATHER_LOCATION_CITY_ID, location.getCityId())
                .put(WEATHER_LOCATION_CITY_NAME, location.getCity()).put(WEATHER_LOCATION_STATE, location.getState())
                .put(WEATHER_LOCATION_POSTAL_CODE, location.getPostalCode())
                .put(WEATHER_LOCATION_COUNTRY_ID, location.getCountryId())
                .put(WEATHER_LOCATION_COUNTRY_NAME, location.getCountry());
@@ -191,8 +183,7 @@ public class Preferences {
            boolean serialized = false;
            try {
                // These members always return a value that can be parsed
                jsonObject
                        .put(WEATHER_INFO_CITY, info.getCity())
                jsonObject.put(WEATHER_INFO_CITY, info.getCity())
                        .put(WEATHER_INFO_CONDITION_CODE, info.getConditionCode())
                        .put(WEATHER_INFO_TEMPERATURE, info.getTemperature())
                        .put(WEATHER_INFO_TEMPERATURE_UNIT, info.getTemperatureUnit())
@@ -205,24 +196,21 @@ public class Preferences {
                jsonObject.put(WEATHER_INFO_HUMIDITY, Double.isNaN(humidity) ? "NaN" : humidity);

                double todaysHigh = info.getTodaysHigh();
                jsonObject.put(WEATHER_INFO_TODAYS_HIGH, Double.isNaN(todaysHigh)
                        ? "NaN" : todaysHigh);
                jsonObject.put(WEATHER_INFO_TODAYS_HIGH, Double.isNaN(todaysHigh) ? "NaN" : todaysHigh);

                double todaysLow = info.getTodaysLow();
                jsonObject.put(WEATHER_INFO_TODAYS_LOW, Double.isNaN(todaysLow)
                        ? "NaN" : todaysLow);
                jsonObject.put(WEATHER_INFO_TODAYS_LOW, Double.isNaN(todaysLow) ? "NaN" : todaysLow);

                double windSpeed = info.getWindSpeed();
                double windDirection = info.getWindDirection();
                jsonObject.put(WEATHER_INFO_WIND_SPEED, Double.isNaN(windSpeed) ? "NaN" : windSpeed)
                        .put(WEATHER_INFO_WIND_SPEED_UNIT, info.getWindSpeedUnit())
                        .put(WEATHER_INFO_WIND_SPEED_DIRECTION, Double.isNaN(windDirection)
                                ? "NaN" : windDirection);
                        .put(WEATHER_INFO_WIND_SPEED_DIRECTION, Double.isNaN(windDirection) ? "NaN" : windDirection);

                JSONArray forecastArray = new JSONArray();
                for (WeatherInfo.DayForecast forecast : info.getForecasts()) {
                    JSONObject jsonForecast = new JSONObject()
                            .put(DAY_FORECAST_CONDITION_CODE, forecast.getConditionCode());
                    JSONObject jsonForecast = new JSONObject().put(DAY_FORECAST_CONDITION_CODE,
                            forecast.getConditionCode());

                    double low = forecast.getLow();
                    jsonForecast.put(DAY_FORECAST_LOW, Double.isNaN(low) ? "NaN" : low);
@@ -257,7 +245,8 @@ public class Preferences {
    public static WeatherInfo getCachedWeatherInfo(Context context) {
        final String cachedInfo = getPrefs(context).getString(Constants.WEATHER_DATA, null);

        if (cachedInfo == null) return null;
        if (cachedInfo == null)
            return null;

        String city;
        int conditionCode;
@@ -295,21 +284,26 @@ public class Preferences {
                high = forecast.getDouble(DAY_FORECAST_HIGH);
                code = forecast.getInt(DAY_FORECAST_CONDITION_CODE);
                WeatherInfo.DayForecast.Builder f = new WeatherInfo.DayForecast.Builder(code);
                if (!Double.isNaN(low)) f.setLow(low);
                if (!Double.isNaN(high)) f.setHigh(high);
                if (!Double.isNaN(low))
                    f.setLow(low);
                if (!Double.isNaN(high))
                    f.setHigh(high);
                forecastList.add(f.build());
            }
            WeatherInfo.Builder weatherInfo = new WeatherInfo.Builder(city, temperature, tempUnit)
                    .setWeatherCondition(conditionCode)
                    .setTimestamp(timestamp);
                    .setWeatherCondition(conditionCode).setTimestamp(timestamp);

            if (!Double.isNaN(humidity)) weatherInfo.setHumidity(humidity);
            if (!Double.isNaN(humidity))
                weatherInfo.setHumidity(humidity);
            if (!Double.isNaN(windSpeed) && !Double.isNaN(windDirection)) {
                weatherInfo.setWind(windSpeed, windDirection, windSpeedUnit);
            }
            if (forecastList.size() > 0) weatherInfo.setForecast(forecastList);
            if (!Double.isNaN(todaysHigh)) weatherInfo.setTodaysHigh(todaysHigh);
            if (!Double.isNaN(todaysLow)) weatherInfo.setTodaysLow(todaysLow);
            if (forecastList.size() > 0)
                weatherInfo.setForecast(forecastList);
            if (!Double.isNaN(todaysHigh))
                weatherInfo.setTodaysHigh(todaysHigh);
            if (!Double.isNaN(todaysLow))
                weatherInfo.setTodaysLow(todaysLow);
            return weatherInfo.build();
        } catch (JSONException e) {
        }
@@ -360,8 +354,7 @@ public class Preferences {
        getPrefs(context).edit().putBoolean(ENABLE_LOCATION, true).apply();
    }

    public static boolean getEnableLocation(
            Context context) {
    public static boolean getEnableLocation(Context context) {
        return getPrefs(context).getBoolean(ENABLE_LOCATION, false);
    }

+14 −25
Original line number Diff line number Diff line
@@ -12,17 +12,14 @@ import android.util.AttributeSet;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

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

import cyanogenmod.weather.CMWeatherManager;
import cyanogenmod.weather.WeatherLocation;
import foundation.e.blisslauncher.R;
import foundation.e.blisslauncher.core.Preferences;
import java.util.HashSet;
import java.util.List;

public class CustomLocationPreference extends EditTextPreference
        implements CMWeatherManager.LookupCityRequestListener {
public class CustomLocationPreference extends EditTextPreference implements CMWeatherManager.LookupCityRequestListener {
    public CustomLocationPreference(Context context) {
        super(context);
    }
@@ -49,15 +46,14 @@ public class CustomLocationPreference extends EditTextPreference
        okButton.setOnClickListener(v -> {
            CustomLocationPreference.this.onClick(d, DialogInterface.BUTTON_POSITIVE);
            final String customLocationToLookUp = getEditText().getText().toString();
            if (TextUtils.equals(customLocationToLookUp, "")) return;
            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.setOnCancelListener(dialog -> weatherManager.cancelRequest(mCustomLocationRequestId));
            mCustomLocationRequestId = weatherManager.lookupCity(customLocationToLookUp, CustomLocationPreference.this);
            mProgressDialog.show();
        });
    }
@@ -83,14 +79,10 @@ public class CustomLocationPreference extends EditTextPreference

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

    private CharSequence[] buildItemList(List<WeatherLocation> results) {
@@ -122,8 +114,7 @@ public class CustomLocationPreference extends EditTextPreference
            }
            builder.append(result.getCity());
            if (needCountry) {
                String country = result.getCountry() != null
                        ? result.getCountry() : result.getCountryId();
                String country = result.getCountry() != null ? result.getCountry() : result.getCountryId();
                builder.append(" (").append(country).append(")");
            }
            items[i] = builder.toString();
@@ -147,10 +138,8 @@ public class CustomLocationPreference extends EditTextPreference
        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();
                Toast.makeText(context, context.getString(R.string.weather_retrieve_location_dialog_title),
                        Toast.LENGTH_SHORT).show();
            } else if (locations.size() > 1) {
                handleResultDisambiguation(locations);
            } else {
+13 −9
Original line number Diff line number Diff line
@@ -8,7 +8,6 @@ import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.os.IBinder;
import android.util.Log;

import foundation.e.blisslauncher.core.utils.Constants;

public class DeviceStatusService extends Service {
@@ -21,12 +20,13 @@ public class DeviceStatusService extends Service {
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();

            // Network connection has changed, make sure the weather update service knows about it
            // 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);
                boolean hasConnection = !intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);

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

                Intent i = new Intent(context, WeatherUpdateService.class);
                if (hasConnection) {
@@ -35,10 +35,12 @@ public class DeviceStatusService extends Service {
                    context.stopService(i);
                }
            } else if (Intent.ACTION_SCREEN_OFF.equals(action)) {
                if (D) Log.d(TAG, "onDisplayOff: Cancel pending update");
                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");
                if (D)
                    Log.d(TAG, "onDisplayOn: Reschedule update");
                WeatherUpdateService.scheduleNextUpdate(context, false);
            }
        }
@@ -55,13 +57,15 @@ public class DeviceStatusService extends Service {

    @Override
    public void onDestroy() {
        if (D) Log.d(TAG, "Stopping service");
        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");
        if (D)
            Log.d(TAG, "Starting service");
        return START_STICKY;
    }

Loading