history improvements

This commit is contained in:
Sergey Solovyev 2013-06-25 18:25:47 +04:00
parent e1b0679263
commit 3a67f465ea
5 changed files with 69 additions and 40 deletions

View File

@ -7,40 +7,40 @@
--> -->
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
a:orientation="vertical" a:orientation="horizontal"
style="?cpp_fragment_list_view_item_style" style="?cpp_fragment_list_view_item_style"
a:layout_width="fill_parent" a:layout_width="match_parent"
a:layout_height="fill_parent"> a:layout_height="wrap_content">
<TextView
a:id="@+id/history_time"
a:layout_width="fill_parent"
a:layout_height="fill_parent"
style="@style/history_time" />
<TextView
a:id="@+id/history_item"
a:layout_width="fill_parent"
a:layout_height="fill_parent"
a:textColor="@color/cpp_button_operator_text_color"
style="@style/history_item" />
<LinearLayout <LinearLayout
a:orientation="horizontal" a:orientation="vertical"
a:layout_width="fill_parent" a:layout_width="0dp"
a:layout_height="fill_parent"> a:layout_weight="1"
a:layout_height="wrap_content">
<TextView <TextView
a:layout_width="wrap_content" a:id="@+id/history_time"
a:layout_height="fill_parent" a:layout_width="fill_parent"
a:text="@string/c_history_item_status" a:layout_height="fill_parent"
style="@style/history_item_label" /> style="@style/history_time"/>
<TextView <TextView
a:id="@+id/history_item_status" a:id="@+id/history_item"
a:layout_width="fill_parent" a:layout_width="fill_parent"
a:layout_height="fill_parent" a:layout_height="fill_parent"
style="@style/history_item" /> a:textColor="@color/cpp_button_operator_text_color"
style="@style/history_item"/>
</LinearLayout> </LinearLayout>
<ImageView a:id="@+id/history_item_status_icon"
a:layout_gravity="center_vertical"
a:scaleType="centerInside"
a:padding="6dp"
a:src="@drawable/kb_disk"
a:visibility="invisible"
a:layout_width="wrap_content"
a:layout_height="match_parent"/>
</LinearLayout> </LinearLayout>

View File

@ -26,6 +26,7 @@
style="@style/history_item" /> style="@style/history_item" />
<LinearLayout <LinearLayout
a:id="@+id/history_item_comment_layout"
a:orientation="horizontal" a:orientation="horizontal"
a:layout_width="fill_parent" a:layout_width="fill_parent"
a:layout_height="fill_parent"> a:layout_height="fill_parent">

View File

@ -234,7 +234,7 @@ public class CalculatorActivityHelperImpl extends AbstractCalculatorHelper imple
final ActionBar actionBar = activity.getSupportActionBar(); final ActionBar actionBar = activity.getSupportActionBar();
for (int i = 0; i < actionBar.getTabCount(); i++) { for (int i = 0; i < actionBar.getTabCount(); i++) {
final ActionBar.Tab tab = actionBar.getTabAt(i); final ActionBar.Tab tab = actionBar.getTabAt(i);
if (tab != null && CalculatorFragmentType.plotter.getFragmentTag().equals(tab.getTag())) { if (tab != null && fragmentType.getFragmentTag().equals(tab.getTag())) {
actionBar.setSelectedNavigationItem(i); actionBar.setSelectedNavigationItem(i);
break; break;
} }

View File

@ -12,6 +12,9 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.solovyev.android.calculator.*; import org.solovyev.android.calculator.*;
import static org.solovyev.android.calculator.CalculatorFragmentType.history;
import static org.solovyev.android.calculator.CalculatorFragmentType.saved_history;
/** /**
* User: serso * User: serso
* Date: 12/18/11 * Date: 12/18/11
@ -28,8 +31,8 @@ public class CalculatorHistoryActivity extends SherlockFragmentActivity implemen
activityHelper.onCreate(this, savedInstanceState); activityHelper.onCreate(this, savedInstanceState);
activityHelper.addTab(this, CalculatorFragmentType.history, null, R.id.main_layout); activityHelper.addTab(this, history, null, R.id.main_layout);
activityHelper.addTab(this, CalculatorFragmentType.saved_history, null, R.id.main_layout); activityHelper.addTab(this, saved_history, null, R.id.main_layout);
} }
@Override @Override
@ -67,4 +70,9 @@ public class CalculatorHistoryActivity extends SherlockFragmentActivity implemen
this.finish(); this.finish();
} }
} }
@Nonnull
CalculatorActivityHelper getActivityHelper() {
return activityHelper;
}
} }

View File

@ -10,8 +10,12 @@ import android.content.Context;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import org.solovyev.android.calculator.CalculatorActivityLauncher;
import org.solovyev.android.calculator.CalculatorFragmentType;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.R;
import org.solovyev.common.text.Strings; import org.solovyev.common.text.Strings;
@ -19,6 +23,11 @@ import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import static android.view.View.INVISIBLE;
import static android.view.View.VISIBLE;
import static org.solovyev.android.calculator.CalculatorFragmentType.saved_history;
import static org.solovyev.android.calculator.history.AbstractCalculatorHistoryFragment.isAlreadySaved;
/** /**
* User: serso * User: serso
* Date: 12/18/11 * Date: 12/18/11
@ -42,26 +51,37 @@ public class HistoryArrayAdapter extends ArrayAdapter<CalculatorHistoryState> {
final TextView editor = (TextView) result.findViewById(R.id.history_item); final TextView editor = (TextView) result.findViewById(R.id.history_item);
editor.setText(AbstractCalculatorHistoryFragment.getHistoryText(state)); editor.setText(AbstractCalculatorHistoryFragment.getHistoryText(state));
final View commentLayout = result.findViewById(R.id.history_item_comment_layout);
final TextView commentView = (TextView) result.findViewById(R.id.history_item_comment); final TextView commentView = (TextView) result.findViewById(R.id.history_item_comment);
if (commentView != null) { if (commentLayout != null && commentView != null) {
final String comment = state.getComment(); final String comment = state.getComment();
if (!Strings.isEmpty(comment)) { if (!Strings.isEmpty(comment)) {
commentView.setText(comment); commentView.setText(comment);
commentLayout.setVisibility(VISIBLE);
} else { } else {
commentView.setText(""); commentView.setText(null);
commentLayout.setVisibility(INVISIBLE);
} }
} }
final TextView status = (TextView) result.findViewById(R.id.history_item_status); final ImageView status = (ImageView) result.findViewById(R.id.history_item_status_icon);
if (status != null) { if (status != null) {
if (state.isSaved()) { if (state.isSaved() || isAlreadySaved(state)) {
status.setText(getContext().getString(R.string.c_history_item_saved)); status.getDrawable().setAlpha(180);
status.setVisibility(VISIBLE);
status.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final Context context = getContext();
if(context instanceof CalculatorHistoryActivity) {
final CalculatorHistoryActivity activity = (CalculatorHistoryActivity) context;
activity.getActivityHelper().selectTab(activity, saved_history);
}
}
});
} else { } else {
if (AbstractCalculatorHistoryFragment.isAlreadySaved(state)) { status.setVisibility(INVISIBLE);
status.setText(getContext().getString(R.string.c_history_item_already_saved)); status.setOnClickListener(null);
} else {
status.setText(getContext().getString(R.string.c_history_item_not_saved));
}
} }
} }