Browse Source

Small code cleanup in WhatsNewActivity

Bartosz Przybylski 9 năm trước cách đây
mục cha
commit
f6520fd18a

+ 37 - 15
src/com/owncloud/android/ui/activity/WhatsNewActivity.java

@@ -61,28 +61,37 @@ public class WhatsNewActivity extends Activity {
 	private ProgressIndicator mProgress;
 	private LinearLayout mContentPanel;
 
-	int currentStep = 0;
+	private int mCurrentStep;
 
 	@Override
 	protected void onCreate(Bundle savedInstanceState) {
 		super.onCreate(savedInstanceState);
 		setContentView(R.layout.whats_new_activity);
+
+		mCurrentStep = 0;
 		mProgress = (ProgressIndicator) findViewById(R.id.progressIndicator);
 		mFeaturesToShow = filterFeaturesToShow();
+
 		mProgress.setNumberOfSteps(mFeaturesToShow.length);
+
 		mForwardFinishButton = (ImageButton) findViewById(R.id.forward);
 		mForwardFinishButton.setOnClickListener(new View.OnClickListener() {
 			@Override
 			public void onClick(View view) {
 				if (mProgress.hasNextStep()) {
 					mProgress.animateToNextStep();
-					mContentPanel.animate().x(-mContentPanel.getChildAt(++currentStep).getLeft());
+					mContentPanel.animate().x(-mContentPanel.getChildAt(++mCurrentStep).getLeft());
+				} else if (mProgress.hasPrevStep()) {
+					mProgress.animateToPrevStep();
+					mContentPanel.animate().x(-mContentPanel.getChildAt(--mCurrentStep).getLeft());
 				} else {
 					onFinish();
 					finish();
 				}
 				if (!mProgress.hasNextStep()) {
 					mForwardFinishButton.setImageResource(R.drawable.ic_ok);
+				} else {
+					mForwardFinishButton.setImageResource(R.drawable.ic_menu_forward);
 				}
 			}
 		});
@@ -95,27 +104,26 @@ public class WhatsNewActivity extends Activity {
 			}
 		});
 
-		SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
-		final int lastSeenVersionCode = pref.getInt(KEY_LAST_SEEN_VERSION_CODE, 0);
-		final boolean isFirstRun = lastSeenVersionCode == 0;
 		TextView tv = (TextView)findViewById(R.id.welcomeText);
-		tv.setText(isFirstRun ? R.string.welcome_to_oc_title : R.string.whats_new_title);
+		tv.setText(isFirstRun() ? R.string.welcome_to_oc_title : R.string.whats_new_title);
 
-		DisplayMetrics dm = new DisplayMetrics();
-		getWindowManager().getDefaultDisplay().getMetrics(dm);
 
 		mContentPanel = (LinearLayout)findViewById(R.id.contentPanel);
 		LinearLayout.LayoutParams ll2 = (LinearLayout.LayoutParams) mContentPanel.getLayoutParams();
-		ll2.width = dm.widthPixels*mFeaturesToShow.length;
+		ll2.width = getScreenWidth()*mFeaturesToShow.length;
 		mContentPanel.setLayoutParams(ll2);
-		LayoutInflater inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
 
+		fillContentPanelWithFeatureData();
+	}
+
+	private void fillContentPanelWithFeatureData() {
+		LayoutInflater inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
 
 		for (int i = 0; i < mFeaturesToShow.length; ++i) {
 			FeatureItem item = mFeaturesToShow[i];
 			LinearLayout newElement = (LinearLayout)inflater.inflate(R.layout.whats_new_element, null);
 
-			LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(dm.widthPixels, ViewGroup.LayoutParams.MATCH_PARENT);
+			LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(getScreenWidth(), ViewGroup.LayoutParams.MATCH_PARENT);
 			newElement.setLayoutParams(params);
 
 			mContentPanel.addView(newElement);
@@ -140,6 +148,22 @@ public class WhatsNewActivity extends Activity {
 		editor.apply();
 	}
 
+	private int getScreenWidth() {
+		DisplayMetrics dm = new DisplayMetrics();
+		getWindowManager().getDefaultDisplay().getMetrics(dm);
+		return dm.widthPixels;
+	}
+
+	static private int getLastSeenVersionCode() {
+		SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(MainApp.getAppContext());
+		return pref.getInt(KEY_LAST_SEEN_VERSION_CODE, 0);
+	}
+
+	static private boolean isFirstRun() {
+		return getLastSeenVersionCode() == 0;
+	}
+
+
 	static public void runIfNeeded(Context context) {
 		if (context instanceof WhatsNewActivity)
 			return;
@@ -152,8 +176,8 @@ public class WhatsNewActivity extends Activity {
 		List<FeatureItem> features = new LinkedList<>();
 
 		SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(MainApp.getAppContext());
-		final int lastSeenVersionCode = pref.getInt(KEY_LAST_SEEN_VERSION_CODE, 0);
-		final boolean isFirstRun = lastSeenVersionCode == 0;
+		final int lastSeenVersionCode = getLastSeenVersionCode();
+		final boolean isFirstRun = isFirstRun();
 
 		for (FeatureItem item : featuresToShow) {
 			if (isFirstRun && item.shouldShowOnFirstRun()) {
@@ -173,8 +197,6 @@ public class WhatsNewActivity extends Activity {
 			new FeatureItem(R.drawable.logo, R.string.welcome_feature_3_title,  R.string.welcome_feature_3_text, "1.0.0", true),
 			new FeatureItem(R.drawable.logo, R.string.welcome_feature_4_title,  R.string.welcome_feature_4_text, "1.0.0", true),
 			new FeatureItem(R.drawable.logo, R.string.welcome_feature_5_title,  FeatureItem.doNotShow, "1.0.0", true),
-			new FeatureItem(R.drawable.logo, R.string.welcome_feature_1_title,  FeatureItem.doNotShow, "1.8.3"),
-			new FeatureItem(R.drawable.logo, R.string.welcome_feature_2_title,  FeatureItem.doNotShow, "1.8.4"),
 	};
 
 	static private class FeatureItem {

+ 8 - 3
src/com/owncloud/android/ui/whatsnew/ProgressIndicator.java

@@ -62,19 +62,23 @@ public class ProgressIndicator extends FrameLayout {
 	public void onWindowFocusChanged(boolean hasWindowFocus) {
 		super.onWindowFocusChanged(hasWindowFocus);
 		// This is not the best place to reset steps but I couldn't find a better one
-		resetStep();
+		setStep(mCurrentStep);
 	}
 
 	public boolean hasNextStep() {
 		return mNumberOfSteps > mCurrentStep;
 	}
 
+	public boolean hasPrevStep() {
+		return mCurrentStep > 1;
+	}
+
 	public void animateToNextStep() {
 		animateToStep(++mCurrentStep);
 	}
 
-	public void resetStep() {
-		setStep(1);
+	public void animateToPrevStep() {
+		animateToStep(--mCurrentStep);
 	}
 
 	public void setNumberOfSteps(int steps) {
@@ -94,6 +98,7 @@ public class ProgressIndicator extends FrameLayout {
 		FrameLayout.LayoutParams lp = (LayoutParams) mCurrentProgressDot.getLayoutParams();
 		lp.leftMargin = dot.getLeft();
 		lp.topMargin = dot.getTop();
+		mCurrentProgressDot.setLayoutParams(lp);
 	}
 
 	private void animateToStep(int step) {