Skip to content
This repository has been archived by the owner on Mar 29, 2023. It is now read-only.

Commit

Permalink
Apply light text color for dark theme
Browse files Browse the repository at this point in the history
  • Loading branch information
tranleduy2000 committed Jun 30, 2019
1 parent 6998521 commit 636d473
Show file tree
Hide file tree
Showing 8 changed files with 447 additions and 316 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import com.duy.calculator.history.DatabaseHelper;
import com.duy.ncalc.settings.CalculatorSetting;
import com.duy.ncalc.userinterface.FontManager;
import com.duy.ncalc.userinterface.ThemeEngine;
import com.duy.ncalc.userinterface.ThemeManager;
import com.duy.ncalc.utils.DLog;
import com.kobakei.ratethisapp.RateThisApp;

Expand Down Expand Up @@ -143,9 +143,9 @@ public void onBackPressed() {
*/
protected void setTheme(boolean recreate) {
String name = mCalculatorSetting.getString(getResources().getString(R.string.key_pref_theme), "");
ThemeEngine themeEngine = new ThemeEngine(getApplicationContext());
int themeId = themeEngine.getTheme(name);
if (themeId != ThemeEngine.THEME_NOT_FOUND) {
ThemeManager themeManager = new ThemeManager(getApplicationContext());
int themeId = themeManager.getTheme(name);
if (themeId != ThemeManager.THEME_NOT_FOUND) {
super.setTheme(themeId);
if (recreate) recreate();
Log.d(TAG, "Set theme ok");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import android.app.Activity;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
Expand All @@ -30,6 +32,7 @@

import com.duy.calculator.R;
import com.duy.calculator.history.ResultEntry;
import com.duy.ncalc.userinterface.ThemeManager;
import com.duy.ncalc.utils.ClipboardManager;

import java.util.ArrayList;
Expand All @@ -40,76 +43,41 @@
* adapter for recycle view mResult
*/
public class ResultAdapter extends RecyclerView.Adapter<ResultAdapter.ResultViewHolder> {
final static String TAG = "ResultAdapter";
private Activity mActivity;
private ArrayList<ResultEntry> mResults = new ArrayList<>();
private final static String TAG = "ResultAdapter";
@NonNull
private final LayoutInflater inflater;
private Activity activity;
private ArrayList<ResultEntry> resultEntries = new ArrayList<>();
@Nullable
private OnItemListener listener = null;


public ResultAdapter(Activity activity) {
mActivity = activity;
}

public ArrayList<ResultEntry> getResults() {
return mResults;
}

public void setResults(ArrayList<ResultEntry> mResults) {
this.mResults = mResults;
}

public void addItem(ResultEntry item) {
mResults.add(0, item);
notifyItemInserted(0);
}

public boolean removeItem(int position) {
if (position > mResults.size() - 1) {
return false;
}
mResults.remove(position);
notifyItemRemoved(position);
return true;
}

public ResultEntry getResult(int position) {
if (position > mResults.size() - 1) {
return new ResultEntry("0", "0");
}
return mResults.get(position);
}

public void clear() {
int size = mResults.size();
if (mResults.size() == 1) {
mResults.clear();
notifyItemRemoved(0);
} else {
mResults.clear();
notifyItemRangeRemoved(0, size);
}
this.activity = activity;
this.inflater = LayoutInflater.from(activity);
}

@NonNull
@Override
public ResultViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(mActivity).inflate(R.layout.list_item_result, parent, false);
public ResultViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = inflater.inflate(R.layout.list_item_result, parent, false);
return new ResultViewHolder(view);
}

public void setListener(OnItemListener listener) {
this.listener = listener;
}

@Override
public void onBindViewHolder(final ResultViewHolder holder, int position) {
final ResultEntry item = mResults.get(position);
public void onBindViewHolder(@NonNull final ResultViewHolder holder, int position) {
final ResultEntry item = resultEntries.get(position);
Log.d(TAG, "onBindViewHolder: " + item.getExpression() + " = " + item.getResult());

holder.txtMath.setDarkTextColor(ThemeManager.isLightTheme(activity));
holder.txtResult.setDarkTextColor(ThemeManager.isLightTheme(activity));

holder.txtMath.setText(item.getExpression());
holder.txtResult.setText(item.getResult());

holder.imgCopy.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ClipboardManager.setClipboard(mActivity, item.getResult());
ClipboardManager.setClipboard(activity, item.getResult());
}
});
holder.imgShare.setOnClickListener(new View.OnClickListener() {
Expand All @@ -119,13 +87,13 @@ public void onClick(View v) {
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, item.getExpression() + " = " + item.getResult());
intent.setType("text/plain");
mActivity.startActivity(intent);
activity.startActivity(intent);
}
});
holder.imgEdit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null) listener.onEditExpr(item);
if (listener != null) listener.onEditClick(item);
}
});

Expand All @@ -139,23 +107,52 @@ public void onClick(View v) {

@Override
public int getItemCount() {
return mResults.size();
return resultEntries.size();
}

private void updateEmptyView() {
public void setListener(@Nullable OnItemListener listener) {
this.listener = listener;
}

public ArrayList<ResultEntry> getResults() {
return resultEntries;
}

public interface OnItemListener {
void onItemClickListener(View view, ResultEntry resultEntry);
public void setResults(ArrayList<ResultEntry> mResults) {
this.resultEntries = mResults;
}

public void addItem(ResultEntry item) {
resultEntries.add(0, item);
notifyItemInserted(0);
}

void onItemLongClickListener(View view, ResultEntry resultEntry);
private void removeItem(int position) {
if (position > resultEntries.size() - 1) {
return;
}
resultEntries.remove(position);
notifyItemRemoved(position);
}

public void clear() {
int size = resultEntries.size();
if (resultEntries.size() == 1) {
resultEntries.clear();
notifyItemRemoved(0);
} else {
resultEntries.clear();
notifyItemRangeRemoved(0, size);
}
}

public interface OnItemListener {

void onEditExpr(ResultEntry item);
void onEditClick(ResultEntry item);

}

class ResultViewHolder extends RecyclerView.ViewHolder {
static class ResultViewHolder extends RecyclerView.ViewHolder {
MathView txtMath;
MathView txtResult;
CardView cardView;
Expand All @@ -164,14 +161,14 @@ class ResultViewHolder extends RecyclerView.ViewHolder {
View imgDelete;
View imgEdit;

public ResultViewHolder(View itemView) {
ResultViewHolder(View itemView) {
super(itemView);
txtMath = (MathView) itemView.findViewById(R.id.txt_input);
txtResult = (MathView) itemView.findViewById(R.id.txt_result);
cardView = (CardView) itemView.findViewById(R.id.card_view);
imgShare = (ImageView) itemView.findViewById(R.id.img_share_item);
txtMath = itemView.findViewById(R.id.txt_input);
txtResult = itemView.findViewById(R.id.txt_result);
cardView = itemView.findViewById(R.id.card_view);
imgShare = itemView.findViewById(R.id.img_share_item);

imgCopy = (ImageView) itemView.findViewById(R.id.img_copy_item);
imgCopy = itemView.findViewById(R.id.img_copy_item);
imgDelete = itemView.findViewById(R.id.img_delete_item);
imgEdit = itemView.findViewById(R.id.img_edit);

Expand Down
Loading

0 comments on commit 636d473

Please sign in to comment.