Refactoring

pull/147/head
M66B 7 years ago
parent d69fe560e4
commit bb2bbae1f6

@ -553,7 +553,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
in.close(); in.close();
} }
return Helper.getDebugInfo(R.string.title_crash_info_remark, null, sb.toString(), context).id; return Helper.getDebugInfo(context, R.string.title_crash_info_remark, null, sb.toString()).id;
} finally { } finally {
file.delete(); file.delete();
} }
@ -909,7 +909,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
new SimpleTask<Long>() { new SimpleTask<Long>() {
@Override @Override
protected Long onLoad(Context context, Bundle args) throws IOException { protected Long onLoad(Context context, Bundle args) throws IOException {
return Helper.getDebugInfo(R.string.title_debug_info_remark, null, null, context).id; return Helper.getDebugInfo(context, R.string.title_debug_info_remark, null, null).id;
} }
@Override @Override
@ -1016,8 +1016,8 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
if (tv != null) { if (tv != null) {
tv.setText(item.title); tv.setText(item.title);
tv.setTextColor(Helper.resolveColor(getContext(), tv.setTextColor(Helper.resolveColor(getContext(), item.highlight ? R.attr.colorUnread : android.R.attr.textColorSecondary
item.highlight ? R.attr.colorUnread : android.R.attr.textColorSecondary)); ));
} }
return row; return row;

@ -183,9 +183,9 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
ivSync.setImageResource(folder.synchronize ? R.drawable.baseline_sync_24 : R.drawable.baseline_sync_disabled_24); ivSync.setImageResource(folder.synchronize ? R.drawable.baseline_sync_24 : R.drawable.baseline_sync_disabled_24);
} }
ivSync.setImageTintList(ColorStateList.valueOf( ivSync.setImageTintList(ColorStateList.valueOf(
Helper.resolveColor(context, Helper.resolveColor(context, folder.synchronize && folder.initialize && !EntityFolder.OUTBOX.equals(folder.type)
folder.synchronize && folder.initialize && !EntityFolder.OUTBOX.equals(folder.type) ? R.attr.colorUnread : android.R.attr.textColorSecondary
? R.attr.colorUnread : android.R.attr.textColorSecondary))); )));
tvKeywords.setText(TextUtils.join(" ", folder.keywords)); tvKeywords.setText(TextUtils.join(" ", folder.keywords));
tvKeywords.setVisibility(debug && folder.keywords.length > 0 ? View.VISIBLE : View.GONE); tvKeywords.setVisibility(debug && folder.keywords.length > 0 ? View.VISIBLE : View.GONE);
@ -378,7 +378,7 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
this.debug = prefs.getBoolean("debug", false); this.debug = prefs.getBoolean("debug", false);
this.dp12 = Helper.dp2pixels(12, context); this.dp12 = Helper.dp2pixels(context, 12);
setHasStableIds(true); setHasStableIds(true);
} }

@ -1705,8 +1705,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
this.confirm = prefs.getBoolean("confirm", false); this.confirm = prefs.getBoolean("confirm", false);
this.debug = prefs.getBoolean("debug", false); this.debug = prefs.getBoolean("debug", false);
this.dp24 = Helper.dp2pixels(24, context); this.dp24 = Helper.dp2pixels(context, 24);
this.textSize = Helper.getTextSize(zoom, context); this.textSize = Helper.getTextSize(context, zoom);
this.colorPrimary = Helper.resolveColor(context, R.attr.colorPrimary); this.colorPrimary = Helper.resolveColor(context, R.attr.colorPrimary);
this.colorAccent = Helper.resolveColor(context, R.attr.colorAccent); this.colorAccent = Helper.resolveColor(context, R.attr.colorAccent);
this.textColorSecondary = Helper.resolveColor(context, android.R.attr.textColorSecondary); this.textColorSecondary = Helper.resolveColor(context, android.R.attr.textColorSecondary);
@ -1726,7 +1726,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
} }
void setZoom(int zoom) { void setZoom(int zoom) {
textSize = Helper.getTextSize(zoom, context); textSize = Helper.getTextSize(context, zoom);
notifyDataSetChanged(); notifyDataSetChanged();
} }

@ -306,9 +306,9 @@ public class FragmentCompose extends FragmentEx {
public void onGlobalLayout() { public void onGlobalLayout() {
int bottom = view.getBottom() int bottom = view.getBottom()
- edit_bar.getHeight() - edit_bar.getHeight()
- Helper.dp2pixels(56, view.getContext()); // full bottom navigation - Helper.dp2pixels(view.getContext(), 56); // full bottom navigation
int remain = bottom - etBody.getTop(); int remain = bottom - etBody.getTop();
int threshold = Helper.dp2pixels(100, view.getContext()); int threshold = Helper.dp2pixels(view.getContext(), 100);
Log.i("Reduce remain=" + remain + " threshold=" + threshold); Log.i("Reduce remain=" + remain + " threshold=" + threshold);
boolean reduce = (remain < threshold); boolean reduce = (remain < threshold);
@ -318,7 +318,7 @@ public class FragmentCompose extends FragmentEx {
? LabelVisibilityMode.LABEL_VISIBILITY_UNLABELED ? LabelVisibilityMode.LABEL_VISIBILITY_UNLABELED
: LabelVisibilityMode.LABEL_VISIBILITY_LABELED); : LabelVisibilityMode.LABEL_VISIBILITY_LABELED);
ViewGroup.LayoutParams params = bottom_navigation.getLayoutParams(); ViewGroup.LayoutParams params = bottom_navigation.getLayoutParams();
params.height = Helper.dp2pixels(reduce ? 36 : 56, view.getContext()); params.height = Helper.dp2pixels(view.getContext(), reduce ? 36 : 56);
bottom_navigation.setLayoutParams(params); bottom_navigation.setLayoutParams(params);
} }
} }
@ -1864,7 +1864,7 @@ public class FragmentCompose extends FragmentEx {
} }
} }
int px = Helper.dp2pixels(12, getContext()); int px = Helper.dp2pixels(getContext(), 12);
Drawable d = getContext().getResources().getDrawable(R.drawable.baseline_broken_image_24, getContext().getTheme()); Drawable d = getContext().getResources().getDrawable(R.drawable.baseline_broken_image_24, getContext().getTheme());
d.setBounds(0, 0, px, px); d.setBounds(0, 0, px, px);
return d; return d;

@ -498,7 +498,7 @@ public class FragmentMessages extends FragmentEx {
boolean inbox = (EntityFolder.ARCHIVE.equals(message.folderType) || EntityFolder.TRASH.equals(message.folderType)); boolean inbox = (EntityFolder.ARCHIVE.equals(message.folderType) || EntityFolder.TRASH.equals(message.folderType));
View itemView = viewHolder.itemView; View itemView = viewHolder.itemView;
int margin = Helper.dp2pixels(12, getContext()); int margin = Helper.dp2pixels(getContext(), 12);
if (dX > margin) { if (dX > margin) {
// Right swipe // Right swipe

@ -172,12 +172,12 @@ public class Helper {
return intent; return intent;
} }
static int dp2pixels(int dp, Context context) { static int dp2pixels(Context context, int dp) {
float scale = context.getResources().getDisplayMetrics().density; float scale = context.getResources().getDisplayMetrics().density;
return Math.round(dp * scale); return Math.round(dp * scale);
} }
static float getTextSize(int zoom, Context context) { static float getTextSize(Context context, int zoom) {
TypedArray ta = null; TypedArray ta = null;
try { try {
if (zoom == 0) if (zoom == 0)
@ -254,7 +254,7 @@ public class Helper {
new SimpleTask<Long>() { new SimpleTask<Long>() {
@Override @Override
protected Long onLoad(Context context, Bundle args) throws Throwable { protected Long onLoad(Context context, Bundle args) throws Throwable {
return getDebugInfo(R.string.title_crash_info_remark, ex, null, context).id; return getDebugInfo(context, R.string.title_crash_info_remark, ex, null).id;
} }
@Override @Override
@ -280,7 +280,7 @@ public class Helper {
ApplicationEx.writeCrashLog(context, ex); ApplicationEx.writeCrashLog(context, ex);
} }
static EntityMessage getDebugInfo(int title, Throwable ex, String log, Context context) throws IOException { static EntityMessage getDebugInfo(Context context, int title, Throwable ex, String log) throws IOException {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append(context.getString(title)).append("\n\n\n\n"); sb.append(context.getString(title)).append("\n\n\n\n");
sb.append(Helper.getAppInfo(context)); sb.append(Helper.getAppInfo(context));
@ -312,11 +312,11 @@ public class Helper {
draft.id = db.message().insertMessage(draft); draft.id = db.message().insertMessage(draft);
draft.write(context, body); draft.write(context, body);
attachSettings(draft.id, 1, context); attachSettings(context, draft.id, 1);
attachNetworkInfo(draft.id, 2, context); attachNetworkInfo(context, draft.id, 2);
attachLog(draft.id, 3, context); attachLog(context, draft.id, 3);
attachOperations(draft.id, 4, context); attachOperations(context, draft.id, 4);
attachLogcat(draft.id, 5, context); attachLogcat(context, draft.id, 5);
EntityOperation.queue(db, draft, EntityOperation.ADD); EntityOperation.queue(db, draft, EntityOperation.ADD);
@ -376,7 +376,7 @@ public class Helper {
return sb; return sb;
} }
private static void attachSettings(long id, int sequence, Context context) throws IOException { private static void attachSettings(Context context, long id, int sequence) throws IOException {
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
EntityAttachment ops = new EntityAttachment(); EntityAttachment ops = new EntityAttachment();
@ -410,7 +410,7 @@ public class Helper {
} }
} }
private static void attachNetworkInfo(long id, int sequence, Context context) throws IOException { private static void attachNetworkInfo(Context context, long id, int sequence) throws IOException {
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
EntityAttachment ops = new EntityAttachment(); EntityAttachment ops = new EntityAttachment();
@ -449,7 +449,7 @@ public class Helper {
} }
} }
private static void attachLog(long id, int sequence, Context context) throws IOException { private static void attachLog(Context context, long id, int sequence) throws IOException {
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
EntityAttachment log = new EntityAttachment(); EntityAttachment log = new EntityAttachment();
@ -483,7 +483,7 @@ public class Helper {
} }
} }
private static void attachOperations(long id, int sequence, Context context) throws IOException { private static void attachOperations(Context context, long id, int sequence) throws IOException {
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
EntityAttachment ops = new EntityAttachment(); EntityAttachment ops = new EntityAttachment();
@ -521,7 +521,7 @@ public class Helper {
} }
} }
private static void attachLogcat(long id, int sequence, Context context) throws IOException { private static void attachLogcat(Context context, long id, int sequence) throws IOException {
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
EntityAttachment logcat = new EntityAttachment(); EntityAttachment logcat = new EntityAttachment();

@ -109,7 +109,7 @@ public class HtmlHelper {
} }
static Drawable decodeImage(String source, Context context, long id, boolean show) { static Drawable decodeImage(String source, Context context, long id, boolean show) {
int px = Helper.dp2pixels(48, context); int px = Helper.dp2pixels(context, 48);
if (TextUtils.isEmpty(source)) { if (TextUtils.isEmpty(source)) {
Drawable d = context.getResources().getDrawable(R.drawable.baseline_broken_image_24, context.getTheme()); Drawable d = context.getResources().getDrawable(R.drawable.baseline_broken_image_24, context.getTheme());

Loading…
Cancel
Save