Refactoring

This commit is contained in:
M66B 2018-12-30 14:35:19 +00:00
parent d69fe560e4
commit bb2bbae1f6
7 changed files with 31 additions and 31 deletions

View File

@ -553,7 +553,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
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 {
file.delete();
}
@ -909,7 +909,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
new SimpleTask<Long>() {
@Override
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
@ -1016,8 +1016,8 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
if (tv != null) {
tv.setText(item.title);
tv.setTextColor(Helper.resolveColor(getContext(),
item.highlight ? R.attr.colorUnread : android.R.attr.textColorSecondary));
tv.setTextColor(Helper.resolveColor(getContext(), item.highlight ? R.attr.colorUnread : android.R.attr.textColorSecondary
));
}
return row;

View File

@ -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.setImageTintList(ColorStateList.valueOf(
Helper.resolveColor(context,
folder.synchronize && folder.initialize && !EntityFolder.OUTBOX.equals(folder.type)
? R.attr.colorUnread : android.R.attr.textColorSecondary)));
Helper.resolveColor(context, folder.synchronize && folder.initialize && !EntityFolder.OUTBOX.equals(folder.type)
? R.attr.colorUnread : android.R.attr.textColorSecondary
)));
tvKeywords.setText(TextUtils.join(" ", folder.keywords));
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);
this.debug = prefs.getBoolean("debug", false);
this.dp12 = Helper.dp2pixels(12, context);
this.dp12 = Helper.dp2pixels(context, 12);
setHasStableIds(true);
}

View File

@ -1705,8 +1705,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
this.confirm = prefs.getBoolean("confirm", false);
this.debug = prefs.getBoolean("debug", false);
this.dp24 = Helper.dp2pixels(24, context);
this.textSize = Helper.getTextSize(zoom, context);
this.dp24 = Helper.dp2pixels(context, 24);
this.textSize = Helper.getTextSize(context, zoom);
this.colorPrimary = Helper.resolveColor(context, R.attr.colorPrimary);
this.colorAccent = Helper.resolveColor(context, R.attr.colorAccent);
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) {
textSize = Helper.getTextSize(zoom, context);
textSize = Helper.getTextSize(context, zoom);
notifyDataSetChanged();
}

View File

@ -306,9 +306,9 @@ public class FragmentCompose extends FragmentEx {
public void onGlobalLayout() {
int bottom = view.getBottom()
- 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 threshold = Helper.dp2pixels(100, view.getContext());
int threshold = Helper.dp2pixels(view.getContext(), 100);
Log.i("Reduce remain=" + remain + " threshold=" + threshold);
boolean reduce = (remain < threshold);
@ -318,7 +318,7 @@ public class FragmentCompose extends FragmentEx {
? LabelVisibilityMode.LABEL_VISIBILITY_UNLABELED
: LabelVisibilityMode.LABEL_VISIBILITY_LABELED);
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);
}
}
@ -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());
d.setBounds(0, 0, px, px);
return d;

View File

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

View File

@ -172,12 +172,12 @@ public class Helper {
return intent;
}
static int dp2pixels(int dp, Context context) {
static int dp2pixels(Context context, int dp) {
float scale = context.getResources().getDisplayMetrics().density;
return Math.round(dp * scale);
}
static float getTextSize(int zoom, Context context) {
static float getTextSize(Context context, int zoom) {
TypedArray ta = null;
try {
if (zoom == 0)
@ -254,7 +254,7 @@ public class Helper {
new SimpleTask<Long>() {
@Override
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
@ -280,7 +280,7 @@ public class Helper {
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();
sb.append(context.getString(title)).append("\n\n\n\n");
sb.append(Helper.getAppInfo(context));
@ -312,11 +312,11 @@ public class Helper {
draft.id = db.message().insertMessage(draft);
draft.write(context, body);
attachSettings(draft.id, 1, context);
attachNetworkInfo(draft.id, 2, context);
attachLog(draft.id, 3, context);
attachOperations(draft.id, 4, context);
attachLogcat(draft.id, 5, context);
attachSettings(context, draft.id, 1);
attachNetworkInfo(context, draft.id, 2);
attachLog(context, draft.id, 3);
attachOperations(context, draft.id, 4);
attachLogcat(context, draft.id, 5);
EntityOperation.queue(db, draft, EntityOperation.ADD);
@ -376,7 +376,7 @@ public class Helper {
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);
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);
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);
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);
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);
EntityAttachment logcat = new EntityAttachment();

View File

@ -109,7 +109,7 @@ public class HtmlHelper {
}
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)) {
Drawable d = context.getResources().getDrawable(R.drawable.baseline_broken_image_24, context.getTheme());