Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public Integer getPopupTheme() {
return popupTheme;
}

}, new ShakyFlowCallback() {
}, null, new ShakyFlowCallback() {
@Override
public void onShakyStarted(@ShakyFlowCallback.ShakyStartedReason int reason) {
Log.d(TAG, "onShakyStarted: " + reason);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class FeedbackActivity extends AppCompatActivity {
static final String SUBCATEGORY = "subcategory";
static final String THEME = "theme";
static final int MISSING_RESOURCE = 0;
static final String SHAKY_CONFIGS = "shakyConfigs";

private Uri imageUri;
private @FeedbackItem.FeedbackType int feedbackType;
Expand All @@ -59,11 +60,13 @@ public static Intent newIntent(@NonNull Context context,
@Nullable Uri screenshotUri,
@Nullable Bundle userData,
@MenuRes int resMenu,
@Nullable Bundle shakyConfigs,
@StyleRes int theme) {
Intent intent = new Intent(context, FeedbackActivity.class);
intent.putExtra(SCREENSHOT_URI, screenshotUri);
intent.putExtra(USER_DATA, userData);
intent.putExtra(RES_MENU, resMenu);
intent.putExtra(SHAKY_CONFIGS, shakyConfigs);
intent.putExtra(THEME, theme);
return intent;
}
Expand All @@ -80,12 +83,22 @@ public void onCreate(Bundle savedInstanceState) {
imageUri = getIntent().getParcelableExtra(SCREENSHOT_URI);
userData = getIntent().getBundleExtra(USER_DATA);
resMenu = getIntent().getIntExtra(RES_MENU, FormFragment.DEFAULT_MENU);
Bundle shakyConfigs = getIntent().getBundleExtra(SHAKY_CONFIGS);

if (savedInstanceState == null) {
getSupportFragmentManager()
if (shakyConfigs != null && shakyConfigs.getBoolean(ShakyConfigConstants.IS_USER_ALUMNI))
{
// Directly opening the "Bug Report" screen for Alumni users
startFormFragment(FeedbackItem.BUG, false);
if (imageUri != null) {
startDrawFragment();
}
} else {
getSupportFragmentManager()
.beginTransaction()
.add(R.id.shaky_fragment_container, SelectFragment.newInstance(customTheme))
.commit();
}
}
}

Expand Down Expand Up @@ -121,37 +134,47 @@ public void onBackPressed() {
*
* @param fragment Fragment the fragment to swap to
*/
private void changeToFragment(@NonNull Fragment fragment) {
getSupportFragmentManager().beginTransaction()
private void changeToFragment(@NonNull Fragment fragment, boolean shouldAddToBackStack) {
FragmentTransaction fragmentTransaction = getSupportFragmentManager()
.beginTransaction()
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.replace(R.id.shaky_fragment_container, fragment)
.addToBackStack(null)
.commit();
.replace(R.id.shaky_fragment_container, fragment);

if (shouldAddToBackStack) {
fragmentTransaction.addToBackStack(null);
}

fragmentTransaction.commit();
}

/**
* Swap the view container for a form fragment, restores the previous fragment if one exists.
*/
private void startFormFragment(@FeedbackItem.FeedbackType int feedbackType) {
private void startFormFragment(
@FeedbackItem.FeedbackType int feedbackType,
boolean shouldAddToBackStack
) {
String title = getString(getTitleResId(feedbackType));
String hint = getString(getHintResId(feedbackType));
String[] subtypes = null;
if (feedbackType == FeedbackItem.BUG) {
subtypes = new String[]{Subcategories.Bug.CRASH, Subcategories.Bug.NON_FATAL};
}
changeToFragment(new FormFragment.Builder(title, hint)
.setScreenshotUri(imageUri)
.setMenu(resMenu)
.setSubtypes(subtypes != null ? R.array.shaky_bug_subcategories : null, subtypes)
.setTheme(customTheme)
.build());
.setScreenshotUri(imageUri)
.setMenu(resMenu)
.setSubtypes(subtypes != null ? R.array.shaky_bug_subcategories : null, subtypes)
.setTheme(customTheme)
.build(),
shouldAddToBackStack
);
}

/**
* Swap the view container for a draw fragment, restores the previous fragment if one exists.
*/
private void startDrawFragment() {
changeToFragment(DrawFragment.newInstance(imageUri, customTheme));
changeToFragment(DrawFragment.newInstance(imageUri, customTheme), true);
}

private void setFeedbackType(@FeedbackItem.FeedbackType int feedbackType) {
Expand All @@ -167,7 +190,7 @@ public void onReceive(Context context, Intent intent) {

setFeedbackType(feedbackType);

startFormFragment(feedbackType);
startFormFragment(feedbackType, true);
if (imageUri != null && feedbackType == FeedbackItem.BUG) {
startDrawFragment();
}
Expand Down
17 changes: 14 additions & 3 deletions shaky/src/main/java/com/linkedin/android/shaky/Shaky.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,18 @@ public class Shaky implements ShakeDetector.Listener {
private long lastShakeTime;
private CollectDataTask collectDataTask;

Shaky(@NonNull Context context, @NonNull ShakeDelegate delegate, @Nullable ShakyFlowCallback callback) {
@Nullable
private final Bundle shakyConfigs;

Shaky(@NonNull Context context,
@NonNull ShakeDelegate delegate,
@Nullable Bundle shakyConfigs,
@Nullable ShakyFlowCallback callback
) {
appContext = context.getApplicationContext();
this.delegate = delegate;
this.shakyFlowCallback = callback;
this.shakyConfigs = shakyConfigs;
shakeDetector = new ShakeDetector(this);

shakeDetector.setSensitivity(getDetectorSensitivityLevel());
Expand All @@ -88,7 +96,7 @@ public class Shaky implements ShakeDetector.Listener {
*/
@NonNull
public static Shaky with(@NonNull Application application, @NonNull ShakeDelegate delegate) {
return with(application, delegate, null);
return with(application, delegate, null, null);
}

/**
Expand All @@ -99,8 +107,10 @@ public static Shaky with(@NonNull Application application, @NonNull ShakeDelegat
@NonNull
public static Shaky with(@NonNull Application application,
@NonNull ShakeDelegate delegate,
@Nullable Bundle shakyConfigs,
@Nullable ShakyFlowCallback callback) {
Shaky shaky = new Shaky(application.getApplicationContext(), delegate, callback);
Shaky shaky =
new Shaky(application.getApplicationContext(), delegate, shakyConfigs, callback);
LifecycleCallbacks lifecycleCallbacks = new LifecycleCallbacks(shaky);
application.registerActivityLifecycleCallbacks(lifecycleCallbacks);
return shaky;
Expand Down Expand Up @@ -326,6 +336,7 @@ private void startFeedbackActivity(@NonNull Result result) {
result.getScreenshotUri(),
result.getData(),
delegate.resMenu,
shakyConfigs,
delegate.getTheme() != null ? delegate.getTheme() : FeedbackActivity.MISSING_RESOURCE);
activity.startActivity(intent);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Copyright (C) 2016 LinkedIn Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.linkedin.android.shaky;

/**
* A class to hold keys for shaky configuration.
*/
public class ShakyConfigConstants {
public static final String IS_USER_ALUMNI = "isUserAlumni";
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void setUp() {
when(activity.getMainLooper()).thenReturn(Looper.getMainLooper());
when(delegate.getSensitivityLevel()).thenReturn(ShakeDelegate.SENSITIVITY_LIGHT);

shaky = new Shaky(activity, delegate, null);
shaky = new Shaky(activity, delegate, null, null);
shaky.setActivity(activity);
}

Expand Down
Loading