Commit 08052f12 authored by Amit Kumar's avatar Amit Kumar 💻 Committed by Romain Hunault

Fix: Crash when exiting app while rotating the device

parent 765a35f9
......@@ -43,6 +43,9 @@ build/
.idea/tasks.xml
.idea/modules.xml
.idea/assetWizardSettings.xml
.idea/markdown-navigator*
projectFilesBackup/
gradle.xml
.classpath
......
......@@ -12,9 +12,6 @@
<option name="NAME_COUNT_TO_USE_STAR_IMPORT" value="2147483647" />
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</JetCodeStyleSettings>
<MarkdownNavigatorCodeStyleSettings>
<option name="RIGHT_MARGIN" value="72" />
</MarkdownNavigatorCodeStyleSettings>
<XML>
<option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" />
</XML>
......
......@@ -62,7 +62,7 @@
android:configChanges="keyboard|keyboardHidden|mcc|mnc|navigation|orientation|screenSize|screenLayout|smallestScreenSize"
android:launchMode="singleTask"
android:resumeWhilePausing="true"
android:screenOrientation="nosensor"
android:screenOrientation="portrait"
android:stateNotNeeded="true"
android:theme="@style/HomeScreenTheme"
android:windowSoftInputMode="adjustPan">
......
......@@ -50,8 +50,9 @@ class ShaderBlurDrawable internal constructor(private val blurWallpaperProvider:
blurBitmap = blurWallpaperProvider.placeholder
}
blurBitmap =
if (blurBitmap!!.height > (blurBounds.bottom.toInt() - blurBounds.top.toInt())) {
if (blurBitmap!!.height >= blurBounds.bottom &&
blurBitmap!!.width >= blurBounds.right
) {
Bitmap.createBitmap(
blurBitmap!!,
blurBounds.left.toInt(), blurBounds.top.toInt(),
......@@ -91,8 +92,11 @@ class ShaderBlurDrawable internal constructor(private val blurWallpaperProvider:
blurPath.reset()
blurPath.addRect(
0f, 0f,
blurBounds.right - blurBounds.left, blurBounds.bottom - blurBounds.top, Path.Direction.CW
0f,
0f,
blurBounds.right - blurBounds.left,
blurBounds.bottom - blurBounds.top,
Path.Direction.CW
)
}
......
......@@ -35,7 +35,7 @@ public class PackageAddedRemovedHandler extends BroadcastReceiver {
AppAddEvent event = new AppAddEvent(packageName, user);
EventRelay.getInstance().push(event);
BlissLauncher.getApplication(ctx).getAppProvider().reload();
BlissLauncher.getApplication(ctx).getAppProvider().reload(false);
}
if ("android.intent.action.PACKAGE_CHANGED".equalsIgnoreCase(action)) {
......@@ -49,12 +49,12 @@ public class PackageAddedRemovedHandler extends BroadcastReceiver {
AppChangeEvent event = new AppChangeEvent(packageName, user);
EventRelay.getInstance().push(event);
BlissLauncher.getApplication(ctx).getAppProvider().reload();
BlissLauncher.getApplication(ctx).getAppProvider().reload(false);
}
if ("android.intent.action.PACKAGE_REMOVED".equals(action) && !replacing) {
AppRemoveEvent event = new AppRemoveEvent(packageName, user);
EventRelay.getInstance().push(event);
BlissLauncher.getApplication(ctx).getAppProvider().reload();
BlissLauncher.getApplication(ctx).getAppProvider().reload(false);
}
if("android.intent.action.MEDIA_MOUNTED".equals(action)) {
......
......@@ -73,7 +73,8 @@ class DockGridLayout @JvmOverloads constructor(
}
}
override fun setInsets(insets: WindowInsets) {
override fun setInsets(insets: WindowInsets?) {
if (insets == null) return
val deviceProfile = BlissLauncher.getApplication(mContext).deviceProfile
val lp =
layoutParams as InsettableRelativeLayout.LayoutParams
......
......@@ -543,6 +543,7 @@ public class HorizontalPager extends ViewGroup implements Insettable {
@Override
public void setInsets(WindowInsets insets) {
if(insets == null) return;
InsettableRelativeLayout.LayoutParams lp = (InsettableRelativeLayout.LayoutParams) getLayoutParams();
lp.topMargin = insets.getSystemWindowInsetTop();
setLayoutParams(lp);
......
......@@ -24,6 +24,7 @@ public class InsettableScrollLayout extends ScrollView implements Insettable {
@Override
public void setInsets(WindowInsets insets) {
if(insets == null) return;
int top = getPaddingTop();
int left = getPaddingLeft();
int right = getPaddingRight();
......
......@@ -103,8 +103,11 @@ public class AppProvider {
private boolean mStopped;
private boolean isSdCardReady;
private AppsRepository appsRepository;
private AppProvider(Context context) {
this.mContext = context;
this.appsRepository = AppsRepository.getAppsRepository();
isLoading = false;
initialise();
}
......@@ -202,7 +205,7 @@ public class AppProvider {
synchronized (AppProvider.class) {
if (sInstance == null) {
sInstance = new AppProvider(context);
sInstance.reload();
sInstance.reload(true);
}
}
}
......@@ -213,12 +216,12 @@ public class AppProvider {
return mContext;
}
public synchronized void reload() {
public synchronized void reload(boolean force) {
Log.d(TAG, "reload() called");
isSdCardReady = Utilities.isBootCompleted();
if (mLauncherItems != null && mLauncherItems.size() > 0) {
if (!force && mLauncherItems != null && mLauncherItems.size() > 0) {
mAppsRepository.updateAppsRelay(mLauncherItems);
}
......@@ -460,7 +463,6 @@ public class AppProvider {
}
private List<LauncherItem> prepareDefaultLauncherItems() {
Log.d(TAG, "prepareDefaultLauncherItems() called " + mApplicationItems.size());
List<LauncherItem> mLauncherItems = new ArrayList<>();
List<LauncherItem> pinnedItems = new ArrayList<>();
PackageManager pm = mContext.getPackageManager();
......@@ -501,10 +503,13 @@ public class AppProvider {
});
mLauncherItems.addAll(pinnedItems);
Log.i(TAG, "prepareDefaultLauncherItems: " + mLauncherItems.size());
return mLauncherItems;
}
public AppsRepository getAppsRepository() {
return appsRepository;
}
public void clear() {
this.sInstance = null;
mLauncherItems = new ArrayList<>();
......
......@@ -4,7 +4,6 @@ import android.util.Log;
import java.util.Calendar;
import foundation.e.blisslauncher.BlissLauncher;
import foundation.e.blisslauncher.core.events.AppAddEvent;
import foundation.e.blisslauncher.core.events.AppChangeEvent;
import foundation.e.blisslauncher.core.events.AppRemoveEvent;
......@@ -44,7 +43,7 @@ public class EventsObserverImpl implements EventRelay.EventsObserver<Event> {
launcherActivity.updateAllCalendarIcons(Calendar.getInstance());
break;
case ForceReloadEvent.TYPE:
BlissLauncher.getApplication(launcherActivity).getAppProvider().reload();
launcherActivity.forceReload();
break;
}
}
......
......@@ -9,7 +9,6 @@ import android.animation.ObjectAnimator;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.WallpaperManager;
import android.app.usage.UsageStats;
import android.appwidget.AppWidgetManager;
......@@ -40,7 +39,6 @@ import android.os.UserManager;
import android.provider.Settings;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.DragEvent;
import android.view.Gravity;
import android.view.LayoutInflater;
......@@ -77,6 +75,7 @@ import com.jakewharton.rxbinding3.widget.RxTextView;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
......@@ -245,6 +244,7 @@ public class LauncherActivity extends AppCompatActivity implements
private Configuration oldConfig;
private WallpaperChangeReceiver wallpaperChangeReceiver;
private GestureDetectorCompat mDetector;
private AlertDialog enableLocationDialog;
public static LauncherActivity getLauncher(Context context) {
if (context instanceof LauncherActivity) {
......@@ -358,15 +358,18 @@ public class LauncherActivity extends AppCompatActivity implements
private void createOrUpdateIconGrid() {
getCompositeDisposable().add(
AppsRepository.getAppsRepository().getAppsRelay()
BlissLauncher.getApplication(this)
.getAppProvider()
.getAppsRepository()
.getAppsRelay()
.distinctUntilChanged()
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(new DisposableObserver<List<LauncherItem>>() {
@Override
public void onNext(List<LauncherItem> launcherItems) {
if (launcherItems == null || launcherItems.size() <= 0) {
BlissLauncher.getApplication(LauncherActivity.this).getAppProvider().reload();
} else if(!allAppsDisplayed) {
BlissLauncher.getApplication(LauncherActivity.this).getAppProvider().reload(true);
} else if (!allAppsDisplayed) {
showApps(launcherItems);
}
}
......@@ -476,19 +479,36 @@ public class LauncherActivity extends AppCompatActivity implements
@Override
protected void onDestroy() {
super.onDestroy();
// Unregister active receivers
TimeChangeBroadcastReceiver.unregister(this, timeChangedReceiver);
ManagedProfileBroadcastReceiver.unregister(this, managedProfileReceiver);
LocalBroadcastManager.getInstance(this).unregisterReceiver(mWeatherReceiver);
// Dispose CompositeDisposable
getCompositeDisposable().dispose();
events.unsubscribe();
// Unsubscribe to events
if (events != null) {
events.unsubscribe();
}
// Dismiss Dialog if currently visible to prevent view leakage.
if (enableLocationDialog != null && enableLocationDialog.isShowing()) {
enableLocationDialog.dismiss();
}
// Clear AppProvider
BlissLauncher.getApplication(this).getAppProvider().clear();
// Handover to android system.
super.onDestroy();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
Log.d(TAG, "onConfigurationChanged() called with: newConfig = [" + newConfig + "]");
int diff = newConfig.diff(oldConfig);
// Don't consider any other config changes as of now.
if ((diff & (CONFIG_ORIENTATION | CONFIG_SCREEN_SIZE)) != 0) {
recreate();
}
......@@ -968,7 +988,6 @@ public class LauncherActivity extends AppCompatActivity implements
}
private void subscribeToEvents() {
Log.d(TAG, "subscribeToEvents() called");
events = EventRelay.getInstance();
events.subscribe(new EventsObserverImpl(this));
}
......@@ -1279,7 +1298,6 @@ public class LauncherActivity extends AppCompatActivity implements
}
return false;
});
scrollView.post(() -> scrollView.setInsets(workspace.getRootWindowInsets()));
currentPageNumber = 1;
mHorizontalPager.setCurrentPage(currentPageNumber);
......@@ -1469,7 +1487,6 @@ public class LauncherActivity extends AppCompatActivity implements
} else if (requestCode == STORAGE_PERMISSION_REQUEST_CODE) {
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Log.d(TAG, "Storage permission granted");
BlurWallpaperProvider.Companion.getInstance(getApplicationContext()).updateAsync();
}
}
......@@ -1492,8 +1509,6 @@ public class LauncherActivity extends AppCompatActivity implements
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);
......@@ -1506,8 +1521,8 @@ public class LauncherActivity extends AppCompatActivity implements
startActivityForResult(intent, REQUEST_LOCATION_SOURCE_SETTING);
});
builder.setNegativeButton(R.string.cancel, null);
dialog = builder.create();
dialog.show();
enableLocationDialog = builder.create();
enableLocationDialog.show();
}
@Override
......@@ -3316,6 +3331,11 @@ public class LauncherActivity extends AppCompatActivity implements
}
}
public void forceReload() {
allAppsDisplayed = false;
BlissLauncher.getApplication(this).getAppProvider().getAppsRepository().updateAppsRelay(Collections.emptyList());
}
/**
* Adapter for folder apps.
*/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment