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

Commit 17b9e350 authored by Amit Kumar's avatar Amit Kumar
Browse files

Auto enable weather widget and fix #19

parent be79930b
Loading
Loading
Loading
Loading
Loading
+149 −65
Original line number Diff line number Diff line
@@ -17,80 +17,34 @@ package org.indin.blisslaunchero.features.launcher;

import static android.view.View.GONE;
import static android.view.View.VISIBLE;

import static cyanogenmod.providers.WeatherContract.WeatherColumns.TempUnit.CELSIUS;
import static cyanogenmod.providers.WeatherContract.WeatherColumns.TempUnit.FAHRENHEIT;
import static cyanogenmod.providers.WeatherContract.WeatherColumns.WindSpeedUnit.KPH;
import static cyanogenmod.providers.WeatherContract.WeatherColumns.WindSpeedUnit.MPH;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.indin.blisslaunchero.BlissLauncher;
import org.indin.blisslaunchero.R;
import org.indin.blisslaunchero.features.notification.NotificationRepository;
import org.indin.blisslaunchero.features.notification.NotificationService;
import org.indin.blisslaunchero.features.suggestions.AutoCompleteAdapter;
import org.indin.blisslaunchero.features.suggestions.AutoCompleteService;
import org.indin.blisslaunchero.features.suggestions.AutoCompleteServiceResult;
import org.indin.blisslaunchero.features.usagestats.AppUsageStats;
import org.indin.blisslaunchero.features.weather.ForecastBuilder;
import org.indin.blisslaunchero.features.weather.WeatherIconUtils;
import org.indin.blisslaunchero.features.weather.WeatherPreferences;
import org.indin.blisslaunchero.features.weather.WeatherUpdateService;
import org.indin.blisslaunchero.framework.Alarm;
import org.indin.blisslaunchero.framework.DeviceProfile;
import org.indin.blisslaunchero.framework.Preferences;
import org.indin.blisslaunchero.framework.Utilities;
import org.indin.blisslaunchero.framework.customviews.BlissDragShadowBuilder;
import org.indin.blisslaunchero.framework.customviews.BlissFrameLayout;
import org.indin.blisslaunchero.framework.customviews.BlissInput;
import org.indin.blisslaunchero.framework.customviews.CustomAnalogClock;
import org.indin.blisslaunchero.framework.customviews.HorizontalPager;
import org.indin.blisslaunchero.framework.customviews.SquareFrameLayout;
import org.indin.blisslaunchero.framework.customviews.SquareImageView;
import org.indin.blisslaunchero.framework.database.Storage;
import org.indin.blisslaunchero.framework.database.model.AppItem;
import org.indin.blisslaunchero.framework.database.model.CalendarIcon;
import org.indin.blisslaunchero.framework.events.AppAddEvent;
import org.indin.blisslaunchero.framework.events.AppChangeEvent;
import org.indin.blisslaunchero.framework.events.AppRemoveEvent;
import org.indin.blisslaunchero.framework.network.RetrofitService;
import org.indin.blisslaunchero.framework.utils.AppUtils;
import org.indin.blisslaunchero.framework.utils.GraphicsUtil;
import org.json.JSONArray;
import org.json.JSONObject;

import com.crashlytics.android.Crashlytics;
import com.jakewharton.rxbinding2.widget.RxTextView;

import android.Manifest;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.LayoutTransition;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.usage.UsageStats;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler;
import android.os.Looper;
import android.provider.Settings;
import android.support.annotation.NonNull;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v4.view.PagerAdapter;
@@ -120,6 +74,60 @@ import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import com.crashlytics.android.Crashlytics;
import com.jakewharton.rxbinding2.widget.RxTextView;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.indin.blisslaunchero.BlissLauncher;
import org.indin.blisslaunchero.R;
import org.indin.blisslaunchero.features.notification.NotificationRepository;
import org.indin.blisslaunchero.features.notification.NotificationService;
import org.indin.blisslaunchero.features.suggestions.AutoCompleteAdapter;
import org.indin.blisslaunchero.features.suggestions.AutoCompleteService;
import org.indin.blisslaunchero.features.suggestions.AutoCompleteServiceResult;
import org.indin.blisslaunchero.features.usagestats.AppUsageStats;
import org.indin.blisslaunchero.features.weather.ForecastBuilder;
import org.indin.blisslaunchero.features.weather.WeatherIconUtils;
import org.indin.blisslaunchero.features.weather.WeatherPreferences;
import org.indin.blisslaunchero.features.weather.WeatherUpdateService;
import org.indin.blisslaunchero.framework.Alarm;
import org.indin.blisslaunchero.framework.DeviceProfile;
import org.indin.blisslaunchero.framework.Preferences;
import org.indin.blisslaunchero.framework.Utilities;
import org.indin.blisslaunchero.framework.customviews.BlissDragShadowBuilder;
import org.indin.blisslaunchero.framework.customviews.BlissFrameLayout;
import org.indin.blisslaunchero.framework.customviews.BlissInput;
import org.indin.blisslaunchero.framework.customviews.CustomAnalogClock;
import org.indin.blisslaunchero.framework.customviews.HorizontalPager;
import org.indin.blisslaunchero.framework.customviews.SquareFrameLayout;
import org.indin.blisslaunchero.framework.customviews.SquareImageView;
import org.indin.blisslaunchero.framework.database.Storage;
import org.indin.blisslaunchero.framework.database.model.AppItem;
import org.indin.blisslaunchero.framework.database.model.CalendarIcon;
import org.indin.blisslaunchero.framework.events.AppAddEvent;
import org.indin.blisslaunchero.framework.events.AppChangeEvent;
import org.indin.blisslaunchero.framework.events.AppRemoveEvent;
import org.indin.blisslaunchero.framework.network.RetrofitService;
import org.indin.blisslaunchero.framework.utils.AppUtils;
import org.indin.blisslaunchero.framework.utils.GraphicsUtil;
import org.json.JSONArray;
import org.json.JSONObject;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

import cyanogenmod.weather.WeatherInfo;
import cyanogenmod.weather.util.WeatherUtils;
import io.reactivex.Observable;
@@ -138,6 +146,7 @@ public class LauncherActivity extends AppCompatActivity implements
    public static final int REORDER_TIMEOUT = 350;
    private final static int INVALID = -999;
    private static final String TAG = "DesktopActivity";
    private static final int LOCATION_PERMISSION_REQUEST_CODE = 1;
    public static boolean longPressed;
    private final Alarm mReorderAlarm = new Alarm();
    private final Alarm mDockReorderAlarm = new Alarm();
@@ -188,6 +197,7 @@ public class LauncherActivity extends AppCompatActivity implements
    private View mWeatherSetupTextView;
    private boolean layoutInflationCompleted;
    private boolean allAppsDisplayed;

    private BroadcastReceiver mWeatherReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
@@ -343,9 +353,6 @@ public class LauncherActivity extends AppCompatActivity implements
        super.onResume();
        Log.d(TAG, "onResume() called");
        overridePendingTransition(R.anim.reenter, R.anim.releave);
        if (mWeatherPanel != null && mWeatherSetupTextView != null) {
            createOrUpdateWeatherPanel();
        }
    }

    @Override
@@ -366,19 +373,16 @@ public class LauncherActivity extends AppCompatActivity implements

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onAppAddEvent(AppAddEvent appAddEvent) {
        Log.d(TAG, "onAppAddEvent() called with: appAddEvent = [" + appAddEvent + "]");
        addNewApp(appAddEvent.packageName);
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onAppRemoveEvent(AppRemoveEvent appRemoveEvent) {
        Log.d(TAG, "onAppRemoveEvent() called with: appRemoveEvent = [" + appRemoveEvent + "]");
        removePackageFromLauncher(appRemoveEvent.packageName);
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onAppChangeEvent(AppChangeEvent appChangeEvent) {
        Log.d(TAG, "onAppChangeEvent() called with: appChangeEvent = [" + appChangeEvent + "]");
        updateApp(appChangeEvent.packageName);
    }

@@ -1071,15 +1075,52 @@ public class LauncherActivity extends AppCompatActivity implements
        mWeatherSetupTextView = findViewById(R.id.weather_setup_textview);
        mWeatherPanel = findViewById(R.id.weather_panel);

        createOrUpdateWeatherPanel();

        LocalBroadcastManager.getInstance(this).registerReceiver(mWeatherReceiver, new IntentFilter(
                WeatherUpdateService.ACTION_UPDATE_FINISHED));

        if (!Preferences.useCustomWeatherLocation(this)) {
            if (!WeatherPreferences.hasLocationPermission(this)) {
                String[] permissions = new String[]{Manifest.permission.ACCESS_COARSE_LOCATION};
                requestPermissions(permissions,
                        WeatherPreferences.LOCATION_PERMISSION_REQUEST_CODE);
            } else {
                LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
                if (!lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
                    showLocationEnableDialog();
                } else {
                    startService(new Intent(this, WeatherUpdateService.class)
                            .putExtra(WeatherUpdateService.ACTION_FORCE_UPDATE, true));
        createOrUpdateWeatherPanel();
                }
            }
        } else {
            startService(new Intent(this, WeatherUpdateService.class)
                    .putExtra(WeatherUpdateService.ACTION_FORCE_UPDATE, true));
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions,
            int[] grantResults) {
        if (requestCode == WeatherPreferences.LOCATION_PERMISSION_REQUEST_CODE) {
            if (grantResults.length > 0
                    && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                // We only get here if user tried to enable the preference,
                // hence safe to turn it on after permission is granted
                LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
                if (!lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
                    showLocationEnableDialog();
                } else {
                    startService(new Intent(this, WeatherUpdateService.class)
                            .putExtra(WeatherUpdateService.ACTION_FORCE_UPDATE, true));
                }
            }
        }
    }

    private void createOrUpdateWeatherPanel() {
        if (!Preferences.showWeather(this) || Preferences.getCachedWeatherInfo(this) == null) {
        if (Preferences.getCachedWeatherInfo(this) == null) {
            mWeatherSetupTextView.setVisibility(VISIBLE);
            mWeatherPanel.setVisibility(GONE);
            mWeatherSetupTextView.setOnClickListener(
@@ -1093,6 +1134,7 @@ public class LauncherActivity extends AppCompatActivity implements
    }

    private void updateWeatherPanel(WeatherInfo w) {

        if (mWeatherSetupTextView.getVisibility() == VISIBLE) {
            mWeatherSetupTextView.setVisibility(GONE);
        }
@@ -1174,6 +1216,43 @@ public class LauncherActivity extends AppCompatActivity implements
        ForecastBuilder.buildSmallPanel(this, forecastView, w);
    }

    private void showLocationEnableDialog() {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        final Dialog dialog;

        // Build and show the dialog
        builder.setTitle(R.string.weather_retrieve_location_dialog_title);
        builder.setMessage(R.string.weather_retrieve_location_dialog_message);
        builder.setCancelable(false);
        builder.setPositiveButton(R.string.weather_retrieve_location_dialog_enable_button,
                (dialog1, whichButton) -> {
                    Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                    intent.setFlags(
                            Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivityForResult(intent, 203);
                });
        builder.setNegativeButton(R.string.cancel, null);
        dialog = builder.create();
        dialog.show();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        Log.d(TAG, "onActivityResult() called with: requestCode = [" + requestCode
                + "], resultCode = [" + resultCode + "], data = [" + data + "]");
        if(requestCode == 203){
            LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
            if (!lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
                Toast.makeText(this, "Set custom location in weather wettings.", Toast.LENGTH_SHORT).show();
            } else {
                startService(new Intent(this, WeatherUpdateService.class)
                        .putExtra(WeatherUpdateService.ACTION_FORCE_UPDATE, true));
            }
        }else{
            super.onActivityResult(requestCode, resultCode, data);
        }
    }

    private ObservableSource<AutoCompleteServiceResult> searchForQuery(
            CharSequence charSequence) {
        Log.d(TAG, "searchForQuery() called with: charSequence = [" + charSequence + "]");
@@ -1890,10 +1969,14 @@ public class LauncherActivity extends AppCompatActivity implements
                        }
                    }
                } else if (dragEvent.getAction() == DragEvent.ACTION_DRAG_ENDED) {
                    Log.i(TAG, "onDrag: here it is");
                    if (isDragging) {
                        isDragging = false;
                        Log.i(TAG, "onDrag: here it is2");

                    }
                    if (!dragEvent.getResult()) {
                        Log.i(TAG, "onDrag: here it is3");
                        movingApp.setVisibility(View.VISIBLE);
                        if (mFolderWindowContainer.getVisibility() == View.VISIBLE) {
                            int currentItem = mFolderAppsViewPager.getCurrentItem();
@@ -1908,6 +1991,7 @@ public class LauncherActivity extends AppCompatActivity implements
                            makeAppWobble(movingApp, true, mDock.indexOfChild(movingApp));
                        }
                    }
                    Log.i(TAG, "onDrag: here it is3");

                    if (mWobblingCountDownTimer != null) {
                        mWobblingCountDownTimer.cancel();
+77 −69

File changed.

Preview size limit exceeded, changes collapsed.

+6 −11
Original line number Diff line number Diff line
@@ -15,18 +15,18 @@
 */
package org.indin.blisslaunchero.framework;

import java.util.ArrayList;
import java.util.Locale;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;

import org.indin.blisslaunchero.features.weather.WeatherUtils;
import org.indin.blisslaunchero.framework.utils.Constants;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import java.util.ArrayList;
import java.util.Locale;

import cyanogenmod.weather.WeatherInfo;
import cyanogenmod.weather.WeatherLocation;

@@ -78,11 +78,6 @@ public class Preferences {
        return getPrefs(context).getBoolean(Constants.WEATHER_FIRST_UPDATE, true);
    }

    public static boolean showWeather(Context context) {
        return getPrefs(context).getBoolean(Constants.SHOW_WEATHER, true)
                && WeatherUtils.isWeatherServiceAvailable(context);
    }

    public static int weatherFontColor(Context context) {
        int color = Color.parseColor(getPrefs(context).getString(Constants.WEATHER_FONT_COLOR,
                Constants.DEFAULT_LIGHT_COLOR));
+0 −1
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ public class Constants {
    public static final boolean DEBUG = true;
    public static final String PREF_NAME = "BLISS_LAUNCHER";

    public static final String SHOW_WEATHER = "show_weather";
    public static final String WEATHER_SOURCE = "weather_source";
    public static final String WEATHER_USE_CUSTOM_LOCATION = "weather_use_custom_location";
    public static final String WEATHER_CUSTOM_LOCATION_CITY = "weather_custom_location_city";
+1 −1
Original line number Diff line number Diff line
@@ -116,7 +116,7 @@
    <string name="weather_refresh_interval">Update interval</string>
    <string name="weather_use_metric">Use metric (°C)</string>
    <string name="weather_retrieve_location_dialog_title">Cannot retrieve location!</string>
    <string name="weather_retrieve_location_dialog_message">Network geolocation is disabled.\n\nSet a custom location or enable network location</string>
    <string name="weather_retrieve_location_dialog_message">Network geolocation is disabled.\n\nEnable location to work with Weather widget.</string>
    <string name="weather_retrieve_location_dialog_enable_button">Enable</string>
    <string name="weather_invert_lowhigh">Invert low/high temperatures</string>
    <string name="weather_progress_title">Verifying location</string>
Loading