Skip to content

Commit

Permalink
Final reformat codes.
Browse files Browse the repository at this point in the history
  • Loading branch information
drakeet committed Nov 6, 2015
1 parent c01d78c commit 30d54c3
Show file tree
Hide file tree
Showing 24 changed files with 149 additions and 162 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ public ActiveAndroidStrategy(Class<?> excludedThisClass, Class<?> excludedThisCl


@Override public boolean shouldSkipField(FieldAttributes attributes) {
return attributes.getDeclaringClass()
.equals(excludedThisClassFields);
return attributes.getDeclaringClass().equals(excludedThisClassFields);
}


@Override public boolean shouldSkipClass(Class<?> clazz) {
return clazz != null && (clazz.equals(excludedThisClass) || shouldSkipClass(clazz.getSuperclass()));
return clazz != null && (clazz.equals(excludedThisClass) ||
shouldSkipClass(clazz.getSuperclass()));
}
}
11 changes: 4 additions & 7 deletions app/src/main/java/me/drakeet/meizhi/service/AlarmReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,10 @@ public class AlarmReceiver extends BroadcastReceiver {
@Override public void onReceive(Context context, Intent intent) {
PreferencesLoader loader = new PreferencesLoader(context);
if (loader.getBoolean(R.string.action_notifiable, true)) {
HeadsUpUtils.show(context,
MainActivity.class,
context.getString(R.string.headsup_title),
context.getString(R.string.headsup_content),
R.mipmap.ic_meizhi_150602,
R.mipmap.ic_female,
123123);
HeadsUpUtils.show(context, MainActivity.class,
context.getString(R.string.headsup_title),
context.getString(R.string.headsup_content),
R.mipmap.ic_meizhi_150602, R.mipmap.ic_female, 123123);
}
}
}
4 changes: 2 additions & 2 deletions app/src/main/java/me/drakeet/meizhi/ui/GankFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ private void loadVideoPreview() {
.map(dGanks -> dGanks.get(0))
.observeOn(AndroidSchedulers.mainThread())
.subscribe(dGank -> startPreview(dGank.preview),
throwable -> getOldVideoPreview(new OkHttpClient()));
throwable -> getOldVideoPreview(new OkHttpClient()));
}


Expand Down Expand Up @@ -313,7 +313,7 @@ private void openTodaySubject() {
String url = getString(R.string.url_gank_io) +
String.format("%s/%s/%s", mYear, mMonth, mDay);
Intent intent = WebActivity.newIntent(getActivity(), url,
getString(R.string.action_subject));
getString(R.string.action_subject));
startActivity(intent);
}

Expand Down
49 changes: 23 additions & 26 deletions app/src/main/java/me/drakeet/meizhi/ui/PictureActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,51 +72,48 @@ private void parseIntent() {
super.onCreate(savedInstanceState);
ButterKnife.bind(this);
parseIntent();

// init image view
ViewCompat.setTransitionName(mImageView, TRANSIT_PIC);
Picasso.with(this)
.load(mImageUrl)
.into(mImageView);

Picasso.with(this).load(mImageUrl).into(mImageView);
// set up app bar
setAppBarAlpha(0.7f);
setTitle(mImageTitle);

setupPhotoAttacher();
}


private void setupPhotoAttacher() {
mPhotoViewAttacher = new PhotoViewAttacher(mImageView);
mPhotoViewAttacher.setOnViewTapListener((view, v, v1) -> hideOrShowToolbar());
// @formatter:off
mPhotoViewAttacher.setOnLongClickListener(v -> {
new AlertDialog.Builder(PictureActivity.this).setMessage(getString(R.string.ask_saving_picture))
.setNegativeButton(android.R.string.cancel,
(dialog, which) -> {
dialog.dismiss();
})
.setPositiveButton(android.R.string.ok,
(dialog, which) -> {
saveImageToGallery();
dialog.dismiss();
})
.show();
new AlertDialog.Builder(PictureActivity.this)
.setMessage(getString(R.string.ask_saving_picture))
.setNegativeButton(android.R.string.cancel,
(dialog, which) -> dialog.dismiss())
.setPositiveButton(android.R.string.ok,
(dialog, which) -> {
saveImageToGallery();
dialog.dismiss();
})
.show();
// @formatter:on
return true;
});
}


private void saveImageToGallery() {
// @formatter:off
Subscription s = RxMeizhi.saveImageAndGetPathObservable(this, mImageUrl, mImageTitle)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(uri -> {
File appDir = new File(Environment.getExternalStorageDirectory(),
"Meizhi");
String msg = String.format(getString(R.string.picture_has_save_to),
appDir.getAbsolutePath());
ToastUtils.showShort(msg);
}, error -> ToastUtils.showLong(error.getMessage() + "\n再试试..."));
.observeOn(AndroidSchedulers.mainThread())
.subscribe(uri -> {
File appDir = new File(Environment.getExternalStorageDirectory(), "Meizhi");
String msg = String.format(getString(R.string.picture_has_save_to),
appDir.getAbsolutePath());
ToastUtils.showShort(msg);
}, error -> ToastUtils.showLong(error.getMessage() + "\n再试试..."));
// @formatter:on
addSubscription(s);
}

Expand All @@ -135,7 +132,7 @@ private void saveImageToGallery() {
RxMeizhi.saveImageAndGetPathObservable(this, mImageUrl, mImageTitle)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(uri -> ShareUtils.shareImage(this, uri, "分享妹纸到..."),
error -> ToastUtils.showLong(error.getMessage()));
error -> ToastUtils.showLong(error.getMessage()));
return true;
case R.id.action_save:
saveImageToGallery();
Expand Down
15 changes: 9 additions & 6 deletions app/src/main/java/me/drakeet/meizhi/ui/WebActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ public class WebActivity extends ToolbarActivity {
@Bind(R.id.webView) WebView mWebView;
@Bind(R.id.tv_title) TextSwitcher mTextSwitcher;

Context mContext;
String mUrl, mTitle;
private String mUrl, mTitle;


@Override protected int provideContentViewId() {
Expand All @@ -69,7 +68,8 @@ public class WebActivity extends ToolbarActivity {


/**
* Using newIntent trick, return WebActivity Intent, to avoid `public static` constant
* Using newIntent trick, return WebActivity Intent, to avoid `public static`
* constant
* variable everywhere
*
* @return Intent to start WebActivity
Expand All @@ -85,7 +85,6 @@ public static Intent newIntent(Context context, String extraURL, String extraTit
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ButterKnife.bind(this);
mContext = this;
mUrl = getIntent().getStringExtra(EXTRA_URL);
mTitle = getIntent().getStringExtra(EXTRA_TITLE);

Expand Down Expand Up @@ -201,8 +200,12 @@ private class ChromeClient extends WebChromeClient {
@Override public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
mProgressbar.setProgress(newProgress);
if (newProgress == 100) { mProgressbar.setVisibility(View.GONE); }
else { mProgressbar.setVisibility(View.VISIBLE); }
if (newProgress == 100) {
mProgressbar.setVisibility(View.GONE);
}
else {
mProgressbar.setVisibility(View.VISIBLE);
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
/**
* 参考了 fython/ExpressHelper @{https://github.com/PaperAirplane-Dev-Team/ExpressHelper/blob/master/app%2Fsrc%2Fmain%2Fjava%2Finfo%2Fpapdt%2Fexpress%2Fhelper%2Fui%2Fcommon%2FMyRecyclerViewAdapter.java}
*/
public class AnimRecyclerViewAdapter<T extends RecyclerView.ViewHolder> extends RecyclerView.Adapter<T> {
public class AnimRecyclerViewAdapter<T extends RecyclerView.ViewHolder>
extends RecyclerView.Adapter<T> {

private static final int DELAY = 138;
private int mLastPosition = -1;
Expand All @@ -52,7 +53,8 @@ public void showItemAnim(final View view, final int position) {
if (position > mLastPosition) {
view.setAlpha(0);
view.postDelayed(() -> {
Animation animation = AnimationUtils.loadAnimation(context, R.anim.slide_in_right);
Animation animation = AnimationUtils.loadAnimation(context,
R.anim.slide_in_right);
animation.setAnimationListener(new Animation.AnimationListener() {
@Override public void onAnimationStart(Animation animation) {
view.setAlpha(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public GankListAdapter(List<Gank> gankList) {
showCategory(holder);
}
else {
boolean theCategoryOfLastEqualsToThis = mGankList.get(position - 1).type.equals(mGankList.get(
position).type);
boolean theCategoryOfLastEqualsToThis = mGankList.get(
position - 1).type.equals(mGankList.get(position).type);
if (!theCategoryOfLastEqualsToThis) {
showCategory(holder);
}
Expand All @@ -73,12 +73,10 @@ public GankListAdapter(List<Gank> gankList) {
}
}
holder.category.setText(gank.type);
SpannableStringBuilder builder = new SpannableStringBuilder(gank.desc).append(StringStyleUtils.format(
holder.gank.getContext(),
" (via. " +
gank.who +
")",
R.style.ViaTextAppearance));
SpannableStringBuilder builder = new SpannableStringBuilder(gank.desc).append(
StringStyleUtils.format(holder.gank.getContext(), " (via. " +
gank.who +
")", R.style.ViaTextAppearance));
CharSequence gankText = builder.subSequence(0, builder.length());

holder.gank.setText(gankText);
Expand Down Expand Up @@ -124,8 +122,7 @@ public ViewHolder(View itemView) {
@OnClick(R.id.ll_gank_parent) void onGank(View v) {
Gank gank = mGankList.get(getLayoutPosition());
Intent intent = WebActivity.newIntent(v.getContext(), gank.url, gank.desc);
v.getContext()
.startActivity(intent);
v.getContext().startActivity(intent);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ public GankPagerAdapter(FragmentManager fm, Date date) {
calendar.setTime(mDate);
calendar.add(Calendar.DATE, -position);
return GankFragment.newInstance(calendar.get(Calendar.YEAR),
calendar.get(Calendar.MONTH) + 1,
calendar.get(Calendar.DAY_OF_MONTH));
calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
/**
* Created by drakeet on 6/20/15.
*/
public class MeizhiListAdapter extends RecyclerView.Adapter<MeizhiListAdapter.ViewHolder> {
public class MeizhiListAdapter
extends RecyclerView.Adapter<MeizhiListAdapter.ViewHolder> {

public static final String TAG = "MeizhiListAdapter";

Expand All @@ -63,10 +64,12 @@ public MeizhiListAdapter(Context context, List<Meizhi> meizhiList) {
}


@Override public void onBindViewHolder(final ViewHolder viewHolder, final int position) {
@Override
public void onBindViewHolder(final ViewHolder viewHolder, final int position) {
Meizhi meizhi = mList.get(position);
int limit = 48;
String text = meizhi.desc.length() > limit ? meizhi.desc.substring(0, limit) + "..." : meizhi.desc;
String text = meizhi.desc.length() > limit ? meizhi.desc.substring(0, limit) +
"..." : meizhi.desc;
viewHolder.meizhi = meizhi;
viewHolder.titleView.setText(text);
viewHolder.card.setTag(meizhi.desc);
Expand All @@ -76,7 +79,9 @@ public MeizhiListAdapter(Context context, List<Meizhi> meizhiList) {
.centerCrop()
.into(viewHolder.meizhiView)
.getSize((width, height) -> {
if (!viewHolder.card.isShown()) viewHolder.card.setVisibility(View.VISIBLE);
if (!viewHolder.card.isShown()) {
viewHolder.card.setVisibility(View.VISIBLE);
}
});
}

Expand Down Expand Up @@ -123,9 +128,7 @@ public ViewHolder(View itemView) {
Observable<Bitmap> getBitmapObservable(String url) {
return Observable.defer(() -> {
try {
return Observable.just(Picasso.with(mContext)
.load(url)
.get());
return Observable.just(Picasso.with(mContext).load(url).get());
} catch (IOException e) {
e.printStackTrace();
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ protected void loginGitHub() {
ToastUtils.showLongX2(getString(R.string.tip_login_github));
});
String url = getString(R.string.url_login_github);
Intent intent = WebActivity.newIntent(this, url, getString(R.string.action_github_login));
Intent intent = WebActivity.newIntent(this, url,
getString(R.string.action_github_login));
startActivity(intent);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public abstract class SwipeRefreshBaseActivity extends ToolbarActivity {
private boolean mIsRequestDataRefresh = false;


@Override public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
@Override
public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);
ButterKnife.bind(this);
}
Expand All @@ -52,14 +53,14 @@ public abstract class SwipeRefreshBaseActivity extends ToolbarActivity {
void trySetupSwipeRefresh() {
if (mSwipeRefreshLayout != null) {
mSwipeRefreshLayout.setColorSchemeResources(R.color.refresh_progress_3,
R.color.refresh_progress_2,
R.color.refresh_progress_1);
R.color.refresh_progress_2, R.color.refresh_progress_1);
// do not use lambda!!
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override public void onRefresh() {
requestDataRefresh();
}
});
mSwipeRefreshLayout.setOnRefreshListener(
new SwipeRefreshLayout.OnRefreshListener() {
@Override public void onRefresh() {
requestDataRefresh();
}
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ public class SwipeRefreshFragment extends Fragment {


void trySetupSwipeRefresh(View root) {
mSwipeRefreshLayout = (MultiSwipeRefreshLayout) root.findViewById(R.id.swipe_refresh_layout);
mSwipeRefreshLayout = (MultiSwipeRefreshLayout) root.findViewById(
R.id.swipe_refresh_layout);
if (mSwipeRefreshLayout != null) {
mSwipeRefreshLayout.setColorSchemeResources(R.color.refresh_progress_3,
R.color.refresh_progress_2,
R.color.refresh_progress_1);
R.color.refresh_progress_2, R.color.refresh_progress_1);
mSwipeRefreshLayout.setOnRefreshListener(() -> requestDataRefresh());
}
}
Expand All @@ -61,7 +61,8 @@ public void setRefreshing(boolean refreshing) {
}
if (!refreshing) {
// 防止刷新消失太快,让子弹飞一会儿
mSwipeRefreshLayout.postDelayed(() -> mSwipeRefreshLayout.setRefreshing(false), 1000);
mSwipeRefreshLayout.postDelayed(
() -> mSwipeRefreshLayout.setRefreshing(false), 1000);
}
else {
mSwipeRefreshLayout.setRefreshing(true);
Expand Down
11 changes: 4 additions & 7 deletions app/src/main/java/me/drakeet/meizhi/util/AlarmManagerUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
public class AlarmManagerUtils {

public static void register(Context context) {

Calendar today = Calendar.getInstance();
Calendar now = Calendar.getInstance();

Expand All @@ -47,12 +46,10 @@ public static void register(Context context) {
Intent intent = new Intent("me.drakeet.meizhi.alarm");
intent.setClass(context, AlarmReceiver.class);

PendingIntent pi = PendingIntent.getBroadcast(context,
520,
intent,
PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
PendingIntent broadcast = PendingIntent.getBroadcast(context, 520, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

am.set(AlarmManager.RTC_WAKEUP, today.getTimeInMillis(), pi);
manager.set(AlarmManager.RTC_WAKEUP, today.getTimeInMillis(), broadcast);
}
}
6 changes: 3 additions & 3 deletions app/src/main/java/me/drakeet/meizhi/util/AndroidUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public class AndroidUtils {

public static void copyToClipBoard(Context context, String text, String success) {
ClipData clipData = ClipData.newPlainText("meizhi_copy", text);
ClipboardManager manager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
ClipboardManager manager = (ClipboardManager) context.getSystemService(
Context.CLIPBOARD_SERVICE);
manager.setPrimaryClip(clipData);
Toast.makeText(context, success, Toast.LENGTH_SHORT)
.show();
Toast.makeText(context, success, Toast.LENGTH_SHORT).show();
}
}
Loading

0 comments on commit 30d54c3

Please sign in to comment.